I'm trying to have a script create a cron job that executes another script on reboot. For reasons I am yet to understand, I cannot get this to work.
For the sake of simplicity, this is the snippet I cannot get working.
Script that creates cron job:
#!/bin/bash
crontab /home/user/folder/tmp/crontab-reboot-part-2.txt
Contents of /crontab-reboot-part-2:
@reboot /home/user/folder/script.sh >> /home/user/folder/cron.log 2>&1
Even when manually executing the crontab command before the reboot,
crontab /home/user/folder/tmp/crontab-reboot-part-2.txt
on reboot, the job still doesn't run as cron.log hasn't been created.
Any idea?
Thanks.
Edit: Per @Raffa's comment
ls -l /home/user/folder/script.sh outputs:
-rwxrwxr-x 1 user user 585 Aug 8 06:51 20_run_commissioning.sh
journalctl --grep='cron' --no-pager --since='-1hour' outputs:
-- Logs begin at Thu 2023-08-10 05:28:46 UTC, end at Thu 2023-08-10 13:31:09 UTC. --
Aug 10 13:31:04 ubuntu cron[706]: (CRON) INFO (pidfile fd = 3)
Aug 10 13:31:04 uncommissioned cron[706]: (CRON) INFO (Running @reboot jobs)
Aug 10 05:39:09 uncommissioned systemd[1]: cron.service: Succeeded.
-- Reboot --
Aug 10 05:40:06 uncommissioned cron[728]: (CRON) INFO (pidfile fd = 3)
Aug 10 05:40:06 uncommissioned cron[728]: (CRON) INFO (Running @reboot jobs)
Aug 10 05:40:06 uncommissioned CRON[732]: pam_unix(cron:session): session opened for user user by (uid=0)
Aug 10 05:40:06 uncommissioned CRON[766]: (user) CMD (/home/user/commissioning/20_run_commissioning.sh >> /home/user/commissioning/cron.log 2>&1^M)
Aug 10 05:40:06 uncommissioned CRON[732]: (CRON) info (No MTA installed, discarding output)
Aug 10 05:40:06 uncommissioned CRON[732]: pam_unix(cron:session): session closed for user user