crontab not executing script
I'm trying to launch a script located at /Documents/scripts/startup.sh that only contains the command sudo mount /dev/sda1 /mnt
on startup. I added it to crontab by executing crontab -e
and appending @reboot /Documents/scripts/startup.sh
to the crontab. however on launch, checking /mnt shows that the drive was not mounted. I also verified that crontab was running by doing sudo service cron status
and it is running. I would appreciate any help on the matter.
Edit: Adding log of service
May 02 11:20:24 jovan-desktop CRON[995]: pam_unix(cron:session): session opened for user root by (uid=0)
May 02 11:20:24 jovan-desktop CRON[1036]: (root) CMD (sudo mount dev/sda1 /mnt)
May 02 11:20:24 jovan-desktop CRON[1035]: (jovan) CMD (/home/jovan/Documents/scripts/startup.sh)
May 02 11:20:24 jovan-desktop CRON[996]: (CRON) info (No MTA installed, discarding output)
May 02 11:20:24 jovan-desktop CRON[996]: pam_unix(cron:session): session closed for user jovan
May 02 11:20:24 jovan-desktop sudo[1037]: root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/mount dev/sda1 /mnt
May 02 11:20:24 jovan-desktop sudo[1037]: pam_unix(sudo:session): session opened for user root by (uid=0)
May 02 11:20:24 jovan-desktop sudo[1037]: pam_unix(sudo:session): session closed for user root
May 02 11:20:24 jovan-desktop CRON[995]: (CRON) info (No MTA installed, discarding output)
May 02 11:20:24 jovan-desktop CRON[995]: pam_unix(cron:session): session closed for user root
Thank you.
(root) CMD (sudo mount dev/sda1 /mnt)
This is missing the leading /
in /dev/sda1
(jovan) CMD (/home/jovan/Documents/scripts/startup.sh)
This runs with your (jovan) identity. You can't expect it to somehow guess your password to authenticate to sudo
, can you ;) I would say putting sudo
anywhere in a non-interactive script is wrong.
Note that for mounting filesystems at boot time, there is the /etc/fstab
file. You just add your filesystem there and the startup scripts (or systemd
) will mount it, unless your mark it noauto
.
And last, I would certainly recommend you to install the mail transport agent (even if only one that delivers mail on your machine), in that case you'd get the error message in your mailbox.