Quantcast

Script behaves differently in crontab than in shell

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Script behaves differently in crontab than in shell

deekay
Hi

I have made a simple script hwclock.sh that shall check if a ntp server is synced and then update the hwclock if it is.
It looks like this:

#!/bin/bash
if ntpq -pn | grep "*"; then hwclock -w; fi

In crontab I have this line
*/1 * * * * /home/root/hwclock.sh

If I execute the script in shell, it works. But if the crontab execute it (äI have confirmed that it does run the script) the hwclock does not get updated.

What can be the problem?

many thanks for answers.

BR
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Script behaves differently in crontab than in shell

deekay
Hmmm, looks like the full path to the binaries does the trick....

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Script behaves differently in crontab than in shell

Jonathan Kunkee

In my experience, the environment (including PATH) can be very different under process-spawning daemons like cron and upstart.

My 2c,
Jon

On Feb 27, 2013 12:55 AM, "deekay" <[hidden email]> wrote:
Hmmm, looks like the full path to the binaries does the trick....





--
View this message in context: http://gumstix.8.n6.nabble.com/Script-behaves-differently-in-crontab-than-in-shell-tp4966907p4966908.html
Sent from the Gumstix mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Script behaves differently in crontab than in shell

Akram Hameed
Just so, CRON will generally at best give you HOME and SHELL env vars and little else. Best for you to assume you get nothing for free in your environment, Deekay. You can specify env vars in the crontab if you like, though.

On Thu, Feb 28, 2013 at 2:15 AM, Jonathan Kunkee <[hidden email]> wrote:

In my experience, the environment (including PATH) can be very different under process-spawning daemons like cron and upstart.

My 2c,
Jon

On Feb 27, 2013 12:55 AM, "deekay" <[hidden email]> wrote:
Hmmm, looks like the full path to the binaries does the trick....





--
View this message in context: http://gumstix.8.n6.nabble.com/Script-behaves-differently-in-crontab-than-in-shell-tp4966907p4966908.html
Sent from the Gumstix mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users



------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
gumstix-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gumstix-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Script behaves differently in crontab than in shell

deekay
Indeed. well, it works fine when using full paths to the bins so I stick to that.

Thanks all for you answers!
Loading...