Redirects (>>) not working in bash scripts


I’m now in the process of installing on a different SSD, and working out how to show this post as ‘complete’, or if I should delete it.

I have a fresh install of DietPi ARMv8 64-bit-image installed on a 4GB RPI4 using an SSD for booting and running. It’s main purpose is running Nextcloud and I followed the prompts & guides to install that, and used my backup to install the data & database (I took the opportunity to install a bigger SSD.

I have a number of scripts, which I normally run in crontab, but troubleshoot in the terminal if needed. The line I am having problems with is;

grep -R ${NAME} * >> /mnt/dietpi_userdata/nextcloud_data/nick/files/computer/scripts/DietPiNC/temp/1800s-${NAME}

These scripts were working before my upgrade, but don’t now. However, after searching the forums etc., I think this is probably just a problem affecting my installation, and not a general problem.

grep is working correctly, and produces a list of files matching the search, but although the file 1800s-${NAME} is created, it does not contain the results from grep. I have tried this as ‘sudo’, also ‘sudo -u www-data’, and they still do not work. I have also tried adding ‘–line-buffered’ after grep - again grep works, but the result does not appear in the created file. I’ve tested the script on an old RPI3 which I use for another purpose and is running a different OS, and the script works okay there.

When I was setting up, I initially had a problem with creating my user of ‘nick’ using ‘useradd’, and subsequently had to add a home and bash profile with ‘mkhomedir_helper’ which may be the root of my problem.



UPDATE 28/09/2021 - More strange behaviour has developed - appears I have a defective SSD. Now installing all again to a different disk and, so far, no strange behaviour!