简体   繁体   English

Bash 脚本杀死所有程序并在一分钟后重新启动它们

[英]Bash script to kill all programs and restart them after a minute

I need to write a bash script to kill all programs running on a Linux server and then restarting them, preferably after a minute.我需要编写一个bash脚本来终止在 Linux 服务器上运行的所有程序,然后重新启动它们,最好在一分钟后。

I am new to bash scripting.我是 bash 脚本的新手。 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.设置您的 crontab 在第 n 分钟运行第一个脚本,然后在 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...哎呀,忘记了重新启动它们的部分...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM