crabsticks
Posts: 1
Joined: Wed Sep 05, 2018 7:35 am

cronjob @reboot not working

Wed Sep 05, 2018 7:41 am

Hello,

I'm brand new to using a raspberry pi, I have a pi 3 and I'm trying to have a script start on boot using the crontable. I have added the follwing lines..

* * * * * /home/pi/frame/syncdrives.sh >/dev/null 2>&1 {This line executes every minute as I want it to}
@reboot /home/pi/frame/start_frame.sh {this does nothing!}

I'm sure I'm missing something simple and I would appreciate it if someone could point out my mistake.

Many Thanks

pcmanbob
Posts: 9922
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: cronjob @reboot not working

Wed Sep 05, 2018 11:23 am

Hi.

My first question is always how do you know its doing nothing ?

Cron run any programs started using it in the background so there is no output to any screen.

you check if your script is running by adding this at the start of your script, just after the shebang.

Code: Select all

echo "program start"
then change your cron entry to look like this.

Code: Select all

@reboot /home/pi/frame/start_frame.sh >> /home/pi/log.txt 2>&1
then you should see the log file created and the program start contained within it and any errors as well, if you want to monitor the execution of the script just add more echo lines within the script.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

pfletch101
Posts: 629
Joined: Sat Feb 24, 2018 4:09 am
Location: Buffalo, NY, USA

Re: cronjob @reboot not working

Wed Sep 05, 2018 2:44 pm

crabsticks wrote:
Wed Sep 05, 2018 7:41 am
Hello,

I'm brand new to using a raspberry pi, I have a pi 3 and I'm trying to have a script start on boot using the crontable. I have added the follwing lines..

* * * * * /home/pi/frame/syncdrives.sh >/dev/null 2>&1 {This line executes every minute as I want it to}
@reboot /home/pi/frame/start_frame.sh {this does nothing!}

I'm sure I'm missing something simple and I would appreciate it if someone could point out my mistake.

Many Thanks
In addition to pcmanbob's comments: probably the most common single reason for a script to work from the command line but not as a cron job is that it assumes the normal user environment, many aspects of which (particularly the home directory) are different and/or not present in cron's environment. Either do a cd to wherever you want your home directory to be at the beginning of your script or make all file references in it absolute (e.g. /home/pi/workingdirectory/thisfile).

AntMeN
Posts: 1
Joined: Sun Jan 26, 2020 1:53 pm

Re: cronjob @reboot not working

Sun Jan 26, 2020 2:32 pm

hi ...
... there is an issue in CRON with on @reboot SyntaX...
on debian base distros...
... here the link https://unix.stackexchange.com/question ... s-for-root
I quote the author...
----------------------------
Re: Cron - @reboot jobs not working

Quote Originally Posted by ceallred View Post This is killing me... Tried the wrapper script. Running manually generates the log file... rebooting and the job doesn't run or create log file.

Syslog shows that CRON ran the job... but again, no output and the process isn't running. Jul 15 20:07:45 RavenWing cron[1026]: (CRON) INFO (Running @reboot jobs) Jul 15 20:07:45 RavenWing CRON[1053]: (ceallred) CMD (/home/ceallred/Scripts/run_spideroak.sh > /home/ceallred/Scripts/SpiderOak.log 2>&1 &)

It's seems like cron doesn't like the @reboot command.... Any other ideas?
----------------------------
I hope it help...
if it is... tell us
good luke

pcmanbob
Posts: 9922
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: cronjob @reboot not working

Sun Jan 26, 2020 7:06 pm

AntMeN wrote:
Sun Jan 26, 2020 2:32 pm
hi ...
... there is an issue in CRON with on @reboot SyntaX...
on debian base distros...
... here the link https://unix.stackexchange.com/question ... s-for-root
I quote the author...
----------------------------
Re: Cron - @reboot jobs not working

Quote Originally Posted by ceallred View Post This is killing me... Tried the wrapper script. Running manually generates the log file... rebooting and the job doesn't run or create log file.

Syslog shows that CRON ran the job... but again, no output and the process isn't running. Jul 15 20:07:45 RavenWing cron[1026]: (CRON) INFO (Running @reboot jobs) Jul 15 20:07:45 RavenWing CRON[1053]: (ceallred) CMD (/home/ceallred/Scripts/run_spideroak.sh > /home/ceallred/Scripts/SpiderOak.log 2>&1 &)

It's seems like cron doesn't like the @reboot command.... Any other ideas?
----------------------------
I hope it help...
if it is... tell us
good luke
First you are replying to a thread that's 2 years old and the OP never posted again so is unlikely to see your reply,

secondly there is no problems using @reboot in Cron when running raspbian, be running it as the pi user or the root user, I use it on many of my pi projects to start various python programs and bash scrips.

You do have to take in to consideration that Cron runs a different environment to the command line and all programs are run in background ,

You also have to be aware that Cron may run before things like networking have be established so this has to be taken in to account as well.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Troubleshooting”