I have a bash script that loops through all folders inside a given path and performs some actions.
I now need this script to find the given path by itself, by monitoring a file that I will update from my server.
So, the script has to:
- check if file todo.txt exists
- read the first line of the file
- perform actions inside the folder defined in that first line
- delete todo.txt
- append done.txt with the same line it found in todo.txt
For some reason, when I run the script directly, this works perfect
cd /proper/path/to/todo
FILE=todo.txt
if [ -f $FILE ];
then
FOLDER=$(head -1 $FILE)
echo "path to process:"$FOLDER
fi;
The output is good, the file is read, the output is "path to process: /correct/path/read/from/file"
However, when I set up a cron job to run this script, the $FOLDER variable is empty so the output is just "path to process:"
* * * * * /bin/sh /www/www.mysite.com/myscript.sh >> /www/www.mysite.com/log.txt
Note that: 1. the script IS ran 2. the if [ -f $FILE ] works, so the file is found
It's just the head command that fails.
Any ideas? thanks!