|03-29-2012, 02:12 PM||#1|
Join Date: Jul 2002
Some of my shell scripts don't launch from cron. It's weird.
First off all the scripts work fine when run via terminal.
The script also runs fine when it's run through cron this way: /user/bin/open /path/script.command
But fails when input in cron as /path/script.sh
(Both the .sh and .command work from terminal)
I have about 1/2 a dozen cron jobs running as /path/script.sh SOME RUN FROM THE SAME DIRECTORY! They call and execute from within cron without flaw.
This one script is driving me nuts. I can get it to work by changing it to .command but I want to understand WHY it's not working.
Here is a copy of the script (It's nothing spectacular, I don't really rely on it or need it per se. I just got a bug up my a$$ and decided I wanted it displayed on the desktop (geek tool) for the next few weeks till I find a good deal.)
#!/bin/bash cd ~/Pictures/ if [ -e ~/Pictures/223_556_reloadable.png ] then mv 223_556_reloadable.png 223_556_reloadablebk.png fi # Image location http://gun-deals.com/dailyPrices/223_556_reloadable.png wgetapp=$(which wget) $wgetapp -c http://gun-deals.com/dailyPrices/223_556_reloadable.png if [ -e ~/Pictures/223_556_reloadable.png ] then rm ~/Pictures/223_556_reloadablebk.png else mv ~/Pictures/223_556_reloadablebk.png ~/Pictures/223_556_reloadable.png; exit 0 fi /opt/local/bin/convert ~/Pictures/223_556_reloadable.png -transparent white -negate ~/Pictures/223_556_reloadable.png exit 0
|03-29-2012, 09:59 PM||#2|
Join Date: Jan 2002
The usual cause of this kind of problem is that the execution environment for cron scripts is not the same as that of the Terminal. In particular, the PATH variable is not the same.
So the usual recommendation is to always use full paths for all executables and files referred to in your scripts. And that means to not use ~ for the home folder.
Instead hard-code the path, or (after checking that this works) use $HOME
|03-31-2012, 05:12 AM||#3|
Join Date: Apr 2008
Location: Berkeley CA USA
~ is just a convenient shortcut for $HOME. If $HOME works, so will ~.
Try it for yourself:
~name is, of course, a different animal. That does a dynamic lookup of name's home folder.
|Display Modes||Rate This Thread|