I need to write a bash script to kill all programs running on a Linux server and then restarting them, preferably after a minute.
I am new to bash scripting. Please help.
What you probably want is to write a script that kills your services. Then a second script that launches them. Set your crontab to run the first script on minute n, then second script at n+1. That should clear the existing programs and launch them after one minute.
Killing ALL programs would be...not good...as in system crash probably. But if you were so inclined:
#!/bin/bash
processes=`ps aux -A --no-heading | grep -v "NameOfThisScript" | awk '{print $2}'`
for i in $processes; do
sudo kill -9 $i
done
Ooops, forgot the part about restarting them...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.