I have a script that works when I run it from the command line, but when I schedule it with
cron I get errors that it cannot find files or commands. My question is twofold:
When I schedule a cron job using
crontab -e, does it use my user ID as the basis for its permissions? Or does it use a cron user ID of some sort and its related permissions?
When a cron job is launched, what is the working directory? Is it the directory where I specify the script to run, or a different directory?
Here is my cron job:
15 7 * * * /home/xxxx/Documents/Scripts/email_ip_script.sh
Here is the actual script:
vIP_ADDR="`curl automation.whatismyip.com/n09230945.asp`" echo "$vIP_ADDR" sed "s/IPADDR/$vIP_ADDR/g" template.txt > emailmsg.txt ssmtp XXXXX@gmail.com < emailmsg.txt
Here are the errors I get when I view the
sed: can't read template.txt: No such file or directory /home/xxxx/Documents/Scripts/email_ip_script.sh: line 15: ssmtp: command not found
It cannot find the
template.txt but it resides in the same directory as the script. It also cannot run
ssmtp, but I can as my user. What am I missing to get this to work properly?