In crontab, how do I know which shell it is using?
for example if I want to redirect output how do I know if I need to use &> or >& (bash vs csh)
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
It depends what version of
cron you have, and how it is configured, but usually it is
/bin/sh. Often that is a symlink to something else though, but that is easy to find as you can simply run
ls -l /bin/sh.
You could add a cron entry like:
* * * * * ps -p $$ > /tmp/shelltest
or (if editing
/etc/crontab instead of adding an entry to a per-user crontab as done via
* * * * * username ps -p $$ > /tmp/shelltest
which will tell you via output to
/tmp/shelltest the filename of the shell. If your
cron is properly setup to mail output to you then you can skip the
>/tmp/shelltest to get the information by mail instead of it being dropped into a file.
To be a bit more trixy something like:
* * * * * ls -l /proc/`ps -p $$ | tail -n 1 | xargs | cut -f 1 -d \ `/exe > /tmp/shelltest
should tell you the exact file used. On a typical Debian system this will result in something like:
lrwxrwxrwx 1 dspillett dspillett 0 Mar 14 16:17 /proc/1356/exe -> /bin/dash
showing that cron is using
dash as the default shell in this instance.
To break that command down:
ps -p $$outputs details of the current process (well,
ps's parent process) which will be the shell in this case.
tail -n 1strips away the header row that
xargsis a trick to trim off leading spaces from the line
cutinvocation takes the first field from the like where the deliter is spaces (it is absolutely vital that you include the space between the \ and the backtick)
ls -l /proc/9999/exewhere "9999" is the process ID read from
pswhich lists the file used to create the process because in the '/proc' filesystem
/proc/<pid>/exeis a link to the executable of the process identified by <pid>.