LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   help me understand the difference between cron.daily and crontab -e (http://www.linuxquestions.org/questions/linux-software-2/help-me-understand-the-difference-between-cron-daily-and-crontab-e-674079/)

duderancher 10-03-2008 08:33 PM

help me understand the difference between cron.daily and crontab -e
 
I am running into some inconsistent behavior when testing and then running cron jobs.

If I run a cron job using the "crontab -e" edit, my shell is /bin/sh

If I run the same cron job using the cron.daily (in RHES4), my shell is /bin/bash

Why? And more importantly, can I make the "crontab -e" method use bash instead of sh?

storkus 10-04-2008 03:20 AM

Umm, on every Linux distro I know of, /bin/sh is linked to /bin/bash, so there shouldn't be any difference. The only possible catch may be with Slackware (which I run) which, for a few things (I think primarily during installation, though) uses the "ash" shell, a stripped-down shell that provides VERY basic functionality in exchange for a teeny-weeny roughly 63kB size.

Mike

Mr. C. 10-04-2008 04:27 AM

There is a behavioral difference between /bin/sh and /bin/bash. When called as /bin/sh, bash acts in a more /bin/sh compatible mode.

cron.daily is a bash shell script called another crontab entry, thus the different shells.

cron uses sh; if you want a cron job to use a different shell, add the #!/bin/bash interpret line to the shell script file the cron job calls. Eg:

Code:

$ crontab -l
#minute hour    mday    month  wday    command
58      */2    *      *      *      /home/mrc/bin/dobackups

$ head -4 ~mrc/bin/dobackups
#!/bin/bash

PATH=/usr/local/bin:/bin:/usr/bin:/usr/sbin
export PATH


storkus 10-05-2008 09:21 AM

Wow, looks like I learned something myself here--thanks!

JZL240I-U 10-09-2008 07:05 AM

If this is a non-continuously running machine (workstation, desktop PC) you might be interested in fcron

http://fcron.free.fr/

duderancher 10-09-2008 08:02 AM

Mr C.

I have the #!/bin/bash statement as the first line in the script although I am not sure it solves that problem. Withing the script, I use the "env" command (and sent he output to mail) to check the environmental variables in the script shell. I get the following:

SHELL=/bin/sh
OLDPWD=/root
USER=root
PATH=/usr/bin:/bin
PWD=/data/data_processing/samples
HOME=/root
SHLVL=2
LOGNAME=root
_=/usr/bin/env

I would expect to see the shell = /bin/bash . I don't get it.


JZL,

Thanks for the tip. I will make use of the cron.daily scripts before I try your suggestion but it is good to know I have options.

Thanks
Dan

Mr. C. 10-09-2008 11:20 AM

The SHELL variable indicates a user's preferred shell for launching applications by other applications when they call upon a shell to perform work. It does not override the interpreter line at the top of an executable file. This is often confusing to new users, as they expect SHELL to match the name of their current shell.

duderancher 10-09-2008 11:53 AM

That helps. Thanks.


All times are GMT -5. The time now is 03:06 PM.