|
|
#1 |
|
Prospect
Join Date: Jul 2002
Location: FLA
Posts: 49
|
Cron weirdness
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.) Code:
#!/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 |
|
|
|
|
|
#2 |
|
Site Admin
Join Date: Jan 2002
Location: Montreal
Posts: 31,957
|
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
__________________
hayne.net/macosx.html |
|
|
|
|
|
#3 | |||||||||||||||||||||||
|
MVP
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,016
|
~ is just a convenient shortcut for $HOME. If $HOME works, so will ~. Try it for yourself: HOME=some/funny/string echo ~/xyzzy ~name is, of course, a different animal. That does a dynamic lookup of name's home folder. |
|||||||||||||||||||||||
|
|
|
|
|
#4 |
|
Triple-A Player
Join Date: Jun 2002
Posts: 62
|
exactly. cron referring to ~ is not going to work as expected when run from your user account. full path.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|