CRON uses sh
as its default shell and source
is a Bash shell builtin command so not recognized in whatever sh
is linked to other than Bash which is not the case for system shell (usually Dash by default) ... On the other hand, the equivalent of for the source
command .
should work there ... See demonstration below:
$ echo "$0"
bash
$
$ type . source
. is a shell builtin
source is a shell builtin
$
$
$ sh
$
$ echo "$0"
sh
$
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Jul 11 12:03 /bin/sh -> dash
$
$ type . source
. is a special shell builtin
source: not found
so try changing source
to .
... The same applies to the contents of /home/myname/cronsh.sh
as well. So check its syntax is Dash friendly or alternatively tell CRON to use Bash with SHELL=/bin/bash
set before your cronjob in the crontab file like so:
SHELL=/bin/bash
0 0 * * * source /home/myname/cronsh.sh
It's worth mentioning that you don't generally need to source a Bash script to execute it (unless you deliberately want it to execute in the current invoking shell and not in a sub-shell), but a more preferred way is to invoke the Bash interpreter itself and provide the script file as an argument like so:
0 0 * * * /bin/bash /home/myname/cronsh.sh
... which should also work if you add a shebang to your script specifying the correct interpreter to invoke i.e. #!/bin/bash
and then invoke the script as an executable itself after you give it execution permissions of course like so:
0 0 * * * /home/myname/cronsh.sh
... and that should save you from needing to apply the above mentioned other suggestions.
sh
as its default shell andsource
is abash
shell builtin command so not recognized in whateversh
is linked to other than Bash which is not the case for system shell (usuallydash
by default) ... On the other hand, the equivalent of for thesource
command.
should work there, so try changingsource
to.
/home/myname/cronsh.sh
as well ... So check its syntax isdash
friendly or alternatively tell CRON to use bash withSHELL=/bin/bash
set before your cronjob in the crontab file.