-   Linux - Software (
-   -   help me understand the difference between cron.daily and crontab -e (

duderancher 10-03-2008 09: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 04: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.


Mr. C. 10-04-2008 05: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:


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

$ head -4 ~mrc/bin/dobackups

export PATH

storkus 10-05-2008 10:21 AM

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

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

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

duderancher 10-09-2008 09: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:


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


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.


Mr. C. 10-09-2008 12:20 PM

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 12:53 PM

That helps. Thanks.

All times are GMT -5. The time now is 09:28 PM.