About system time in a bash script - linux

I'm starting work on a bash script that will shutdown my computer at a certain time of day, but I'm not really sure what all specifically needs to go into that. Could someone post an example of how they would do it?

If you want to shut down at 22:15 every day, be root, run crontab -e, then add
15 22 * * * shutdown -h 5
on a line by itself.
Then save. At 22:15 every day, you will get a warning that the system will shut down in 5 minutes, and five minutes later, true to its word, it shuts down. If you want to abort the shutdown, run shutdown -c as root after the warning.

Related

Set time to automatically run and close the program Qt in Pi4

For some reason I need to run a Qt program on my Pi4 between 7am and 10pm, the rest of the time the program closes. This needs to happen automatically every day. I tried but it didn't work, the program couldn't open and close automatically as I wanted. Who can help me?
You can use crontab to run some script to start your program at 7am, then run another script to close the program at 10pm.
For example, add codes below in crontab and you can run and stop some program everyday.
0 7 * * * start.sh
0 22 * * * stop.sh
crontab tutorial

Crontab reboot job reboot multiple times instead of once

I am trying to schedule my debian jessie machine to shutdown at 9:00 p.m. every 3 days. I currently use a cronjob:
00 21 */3 * * root bash /home/pi/scripts/reboot.sh
where reboot.sh is:
sudo reboot
The machine shuts down on schedule but what is strange is that it just keeps rebooting for several times. how am I able to get rid of this issue. is this related to maybe the RTC clock no have enough time to update itself and so the cron job still thinks the time is still 9... I really doubt this.. any help
its better to use the internal command shutdown instead of using the script. shutdown now shuts the computer and -r flag is for reboot system. you can also pass specific time instead of now like shutdown -r 11:00.
For now you can use
shutdown -r now

Using cron Chef cookbook to run a command every 30 mins

I am using the cron cookbook to run every 30 minutes in the following way:
cron_d 'logrotate_check' do
minute "*/30"
command "logrotate -s /var/log/logstatus /etc/logrotate.d/consul_logs"
user 'root'
end
Please let me know if it is correct?
Yes, that is fine. In the future, please just try it yourself rather than asking the internet and waiting 10 hours.

crontab script centos runs daily but also an extra one

CentOS release 6.7
Vanilla install, all I have really done is added to /etc/crontab
59 23 * * * root run-parts /etc/cron.daily
inside /etc/cron.daily is svn.sh which has a single line
/home/svn.sh 2>&1| mail -s "blah" myemailaddy
The final script dumps the database and does a svn commit on the zipfile.
The bizarre thing is that it emails me at 5 minutes past midnight showing the database dump output and the svn commit. Then 4 hours later it runs again for no reason I can understand. Does it every day but what time later can vary (e.g. might be 3.5 hours later)
There is just a single instance of crond running.
What can I look for to troubleshoot this?
So in the end it appears to be the run-parts /etc/cron.daily
not sure how that works, but not well. Replacing that with calling the script directly and it works fine.

Cron scheduled task ignored

I have set a specific cronjob (crontab -e), but it doesn't works like I thought. I don't get what's wrong.
Here is what I do (root cron):
#reboot /path/to/my_script.sh start
25 18 * * * halt
The first line as expected is running my_script.sh, but when time comes for the server to shutdown, nothing happen. Is the #reboot option made to work alone?
There is no option in cron to run at shutdown. #reboot is meant to run the script on start
If you want to run a script at shutdown, you need to write an initd script and register it for the shutdown run level. The standard runlevel for halt is 0, the run level for restart is 6. I've verified this for Debian, Gentoo and Redhat systems but it seems to be true across *NIX systems. Check this for more info.

Resources