Hi
When I setup a cron job like this
crontab -e
*/1 * * * * echo $A_VARIABLE > /home/user/Desktop/test.txt
no problem, the file is created whether the variable exist or not.
BUT doing
*/1 * * * * cd /Path/To/Script && Script.sh
#The Script.sh
echo $A_VARIABLE > /home/user/Desktop/test.txt
Do not generate the file ! and The CRON log give me
(CRON) info (No MTA installed, discaring ouput)
and yes, the Script.sh has the execution bit.
Any ideas ?
Thanks.
If . or /path/to/Script are not in your crontab’s PATH variable, it cannot find the script. If the script is in /path/to/Script, change your crontab to either:
*/1 * * * * cd /Path/To/Script && ./Script.sh
Or
Also, “*/1” means every 1 minute and “*” means every minute, so the “/1” is unnecessary
This is the answer. Everyone assumes your user Crontab works just like you. It doesn’t. You have to be explicit as possible, because it’s basically like another person attempting to run your stuff, but not having any of your environment variables.
So you’re telling it to CD, but calling the script name then tells it to look in it’s path, which it won’t have that. T
he ./ says ‘run from right where I am right now’ while ‘<scriptname>’ says run an executable where ever it is which then immediately checks $PATH, bit not local.
So ‘./<script name>’ says run my script and it’s right HERE in the place you’re in right now.