wjumaat
Posts: 2
Joined: Fri Feb 01, 2019 1:27 am

CRON not executing SH file

Fri Feb 01, 2019 8:07 am

Dear All,

My objective is to restart the PI daily at a fixed time.

I wrote a script using nano.

Code: Select all

nano home/pi/reboot.sh
Then on crontab, I inserted the command

Code: Select all

57 15  * * * chmod +x /home/pi/reboot.sh
Till now, I am still unable to execute the command automatically.

Your advise is much appreciated.
Peace be upon you,
Wandi bin Juma'at

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

Re: CRON not executing SH file

Fri Feb 01, 2019 11:11 am

Hi.

Your cron line is incorrect all that will do is make the file reboot.sh executable.

to actually call the file you would have a cron line like this.

Code: Select all

57 15  * * *  /home/pi/reboot.sh
and you should not call your file reboot.sh as reboot is a command this will just cause your pi to get confused, so you should change the file name to some thing else

examples myreboot.sh, nowreboot.sh
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

User avatar
rpdom
Posts: 14180
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: CRON not executing SH file

Fri Feb 01, 2019 12:15 pm

pcmanbob wrote:
Fri Feb 01, 2019 11:11 am
and you should not call your file reboot.sh as reboot is a command this will just cause your pi to get confused, so you should change the file name to some thing else
Nonsense. reboot.sh is not the same as reboot. Unlike certain other operating systems, Linux uses the whole file name, not just the part before the dot if it is followed by certain other characters. reboot.exe for example.

wjumaat
Posts: 2
Joined: Fri Feb 01, 2019 1:27 am

Re: CRON not executing SH file

Wed Feb 27, 2019 1:53 am

Hi All,
Sorry for the late reply.

I managed to resolve the problem. Perhaps, I guess the issue was that i did not make the sh file executable with the chmod +x command.

Thank you.
Peace be upon you,
Wandi bin Juma'at

raspby66
Posts: 4
Joined: Tue Jan 03, 2017 5:26 am

Re: CRON not executing SH file

Fri May 24, 2019 6:23 am

wjumaat wrote:
Wed Feb 27, 2019 1:53 am
Hi All,
Sorry for the late reply.

I managed to resolve the problem. Perhaps, I guess the issue was that i did not make the sh file executable with the chmod +x command.

Thank you.
Would you mind terribly listing the *complete* commands in your script to have your PI reboot itself on a daily basis. I understand writing that script using nano. But what did you put in the chron file to accomplish the running of the script? Finally would you detail the chmod command for the script? Thanks very much!

Regards!

User avatar
RaTTuS
Posts: 10254
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK

Re: CRON not executing SH file

Fri May 24, 2019 8:10 am

you don't really want to; but if you
sudo crontab -e
57 15 * * * /sbin/reboot

this will reboot your machine at 57 mins pas 15 every day
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

raspby66
Posts: 4
Joined: Tue Jan 03, 2017 5:26 am

Re: CRON not executing SH file

Fri May 24, 2019 2:17 pm

RaTTuS wrote:
Fri May 24, 2019 8:10 am
you don't really want to; but if you
sudo crontab -e
57 15 * * * /sbin/reboot

this will reboot your machine at 57 mins pas 15 every day
Please tell me if the 3 asterisks are supposed to represent something that I must complete or do I type out the whole line just like you have?

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

Re: CRON not executing SH file

Fri May 24, 2019 2:22 pm

raspby66 wrote:
Fri May 24, 2019 2:17 pm
RaTTuS wrote:
Fri May 24, 2019 8:10 am
you don't really want to; but if you
sudo crontab -e
57 15 * * * /sbin/reboot

this will reboot your machine at 57 mins pas 15 every day
Please tell me if the 3 asterisks are supposed to represent something that I must complete or do I type out the whole line just like you have?
Yes the 3 asterisks are supposed to be there they indicate you want the job to run every day , every month and every weekday.

may be helpful is you are new to using cron.

https://www.raspberrypi.org/documentati ... ge/cron.md
https://crontab-generator.org/
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

dl324
Posts: 114
Joined: Mon May 06, 2019 7:33 pm
Location: Pacific Northwest, USA

Re: CRON not executing SH file

Fri May 24, 2019 2:56 pm

raspby66 wrote:
Fri May 24, 2019 2:17 pm
Please tell me if the 3 asterisks are supposed to represent something that I must complete or do I type out the whole line just like you have?
man is your friend.

Code: Select all

man 5 crontab
<snip>
       Commands  are  executed  by cron(8) when the minute, hour, and month of
       year fields match the current time, and when at least one  of  the  two
       day  fields  (day of month, or day of week) match the current time (see
       ``Note'' below).  cron(8) examines cron entries once every minute.  The
       time and date fields are:

              field          allowed values
              -----          --------------
              minute         0-59
              hour           0-23
              day of month   1-31
              month          1-12 (or names, see below)
              day of week    0-7 (0 or 7 is Sun, or use names)

       A field may be an asterisk (*), which always stands for ``first-last''.
The following are special options that are used instead of the first 5 fields

Code: Select all

       Instead  of  the  first  five  fields, one of eight special strings may
       appear:

              string         meaning
              ------         -------
              @reboot        Run once, at startup.
              @yearly        Run once a year, "0 0 1 1 *".
              @annually      (same as @yearly)
              @monthly       Run once a month, "0 0 1 * *".
              @weekly        Run once a week, "0 0 * * 0".
              @daily         Run once a day, "0 0 * * *".
              @midnight      (same as @daily)
              @hourly        Run once an hour, "0 * * * *".

       Please note that startup, as far as @reboot is concerned, is  the  time
       when  the cron(8) daemon startup.  In particular, it may be before some
       system daemons, or other facilities, were startup.  This is due to  the
       boot order sequence of the machine.

Return to “Beginners”