Page 1 of 1

CRON not executing SH file

Posted: Fri Feb 01, 2019 8:07 am
by wjumaat
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.

Re: CRON not executing SH file

Posted: Fri Feb 01, 2019 11:11 am
by pcmanbob
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

Re: CRON not executing SH file

Posted: Fri Feb 01, 2019 12:15 pm
by rpdom
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.

Re: CRON not executing SH file

Posted: Wed Feb 27, 2019 1:53 am
by wjumaat
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.

Re: CRON not executing SH file

Posted: Fri May 24, 2019 6:23 am
by raspby66
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!

Re: CRON not executing SH file

Posted: Fri May 24, 2019 8:10 am
by RaTTuS
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

Re: CRON not executing SH file

Posted: Fri May 24, 2019 2:17 pm
by raspby66
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?

Re: CRON not executing SH file

Posted: Fri May 24, 2019 2:22 pm
by pcmanbob
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/

Re: CRON not executing SH file

Posted: Fri May 24, 2019 2:56 pm
by dl324
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.