How do I schedule a timed reboot of my server in seconds? [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I’m using bash shell on Linux …
$ uname -a
Linux sandbox.mydomain.com 3.4.76-65.111.amzn1.x86_64 #1 SMP Tue Jan 14 21:06:49 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
although it would be nice if I could come up with a solution in any bash supported environment. My question is, in my script I want to scheduled a delayed reboot of my server in 5 seconds. So far, I have the below, but it takes 60 seconds …
# Timed reboot of server
sudo shutdown -r 1
# Fail if any of the sub-deployments failed.
if [[ ( $PROC1_STATUS -ne 0 ) ||
( $PROC2_STATUS -ne 0 ) ||
( $PROC3_STATUS -ne 0 ) ]]
then
exit 1;
fi
Does anyone know how I can adjust the above except make the timed reboot in 5 seconds instead of a minute? The solution doesn't have to use "shutdown" but it was the only tool I could find.
Dave

Try
sleep 5 ; reboot
on your terminal (as root). If you want it in the background, try
( sleep 5 ; reboot ) &
See also shutdown(8)

Related

How to set the output of ^Z (Control-Z) to output the PID of the stopped process? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 months ago.
Improve this question
I start my script bash test.sh and then press Control-Z and get this:
^Z
[1]+ Stopped bash test.sh
All fine. But I want that the output also has the PID.
I know I can do this ps $(jobs -p) afterwards to get the PID. But how it is possible that the output of Control-Z prints directly the PID?
I don't think that's possible. That said, perhaps you can take a step back and clarify why you are hoping to do that?
Because what you can do is directly refer to the particular job with %1 (or %<n> more generally, if you have multiple background jobs) for several built-in commands (fg, bg, kill, ...):
$ sleep 30
^Z
[1]+ Stopped sleep 30
$ kill %1
[1]+ Terminated: 15 sleep 30
More details in man bash or here: https://www.gnu.org/software/bash/manual/bash.html#Job-Control-Basics

Schedule crontab job for last sunday in the month [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
We want to extend our backup system to include a monthly end backup. It will be performed the last Sunday in the month but code below is so that I can see it works today on a smaller scale.
Started with (which works)
0 12 * * 0 sudo tar -cpzf /media/BackupDisk/wwwJUNEbackup.tar.gz /var/www
Have trawled the internet and come up with this code, tested in script file
if [ $(date +%d -d '+7 days') -le '8' ] ; then
echo "Yes"
else
echo "No"
fi
(For reference this says - if today's date + 7 days is less then or equal to 8 then YES else NO)
But when I try to include into the Sudo's crontrab
26 17 * 6 5 [ $(date +%d -d '+7 days') -lt '8' ] && sudo tar -cpzf /media/BackupDisk/wwwJUNEbackup.tar.gz /var/www
I get a nothing.
What am I doing wrong?
Create trivial script last_weekday_in_month.sh and use it in your crontab entry.
You use syntax far beyond basic shell => IMHO it is better to move it to trivial script with specific shell enforced via #!/...
12 * * 0 /path/last_weekday_in.month.sh && sudo tar -cpzf /media/BackupDisk/wwwJUNEbackup.tar.gz /var/www
last_weekday_in.month.sh
#!/bin/bash
if [ $(date +%d -d '+7 days') -lt '8' ] ; then
exit 0
else
exit 1
fi

How do I run `forever` from Crontab? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
I am trying to schedule node server restart on OS reboot (Ubuntu 16.04 LTS). I wrote:
crontab -u username -e
then I added following line:
#reboot /usr/local/bin/forever start -c /usr/bin/node /home/username/node/bin/www
I get the success message after saving or updating this file. There seems to be no effect on server reboot.
I'd wrap that into a bash script in the user's home directory's bin.
/home/username/bin/start_my_node_app.sh
Then in your crontab...
#reboot /home/username/bin/start_my_node_app.sh >/dev/null 2>&1
Though according to this article, #reboot may not work for non-root users.
https://unix.stackexchange.com/questions/109804/crontabs-reboot-only-works-for-root

Why 'ps' command works different in oracle Linux and CentOS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am trying to check whether the pmon process is running or not in CentOS and Oracle Linux over shell command. I used below command.
In CentOS :
ps -e | grep pmon;echo $?
Output
61577 ? 00:00:00 ora_pmon_orcl
0
But, in Oracle Linux:
ps -e | grep pmon;echo $?
Output
1
I am not able to understand why they behave differently.
Can I get a command which will work on both OS as below
1 output for process not running
0 output for process running
Edit: As suggested by Vatine and Dipak
Try running this
ps -ef|grep [p]mon|wc -l|awk '{if ($1 != 0) print "0"; else print "1";}'
It will return 1 if process is not running and 0 if it is running.

Turn off crontab log [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
The log file is located at /var/log/cron. Its size grows too fast and it seems to contain a lot of unimportant data that I would never want to see. So I try to find a way to turn it off but still don't know how.
Here are some more details about the crontab:
crontab -l
*/5 * * * * /usr/sbin/ntpdate 10.0.1.10
*/1 * * * * cd /tmp && netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c > net.tmp && mv -f net.tmp net.cache
*/1 * * * * /script/svrcheck/openvpn.sh > /dev/null 2>&1
tail /var/log/cron
Dec 17 09:25:01 HB04 crond[54509]: (root) CMD (/usr/sbin/ntpdate 10.0.1.10)
Dec 17 09:25:01 HB04 crond[54500]: (root) CMD (/script/svrcheck/openvpn.sh > /dev/null 2>&1)
Dec 17 09:25:01 HB04 crond[54504]: (root) CMD (cd /tmp && netstat -an|awk '/tcp/ {print $6}'|sort|uniq -c > net.tmp && mv -f net.tmp net.cache)
Please let me know if I could provide you more info.
you can control logging using syslog.conf
comment the cron entry inside the syslog.conf as follows .
auth,authpriv.* /var/log/auth.log
*.*;auth,authpriv.none,cron.none -/var/log/syslog
#cron.* /var/log/cron
and restart the syslog.

Resources