利用crontab 定时重启 80端口的服务
定时任务运行的脚本:
jiaoben.sh
#!/bin/bash #tcp deal eval pid80=$(netstat -tlunp | awk '{if($4 == "0.0.0.0:80") print $7} ' | cut -d "/" -f 1) kill -9 $pid80 eval pid8888=$(netstat -tlunp | awk '{if($4 == "0.0.0.0:8888") print $7} ' | cut -d "/" -f 1) kill -9 $pid8888 #tcp6 deal eval pid80=$(netstat -tlunp | awk '{if($4 == ":::80") print $7} ' | cut -d "/" -f 1) kill -9 $pid80 eval pid8888=$(netstat -tlunp | awk '{if($4 == ":::8888") print $7} ' | cut -d "/" -f 1) kill -9 $pid8888 #main job nohup /usr/local/jdk8/jdk1.8.0_151/bin/java -classpath /usr/local/xwhapi/xwhb-api-1.0-SNAPSHOT-jar-with-dependencies.jar run/RunInOneServerVersion 6 ./program >/dev/null 2>/dev/null &
[root@sdfadfasd2123 xwhapi]# netstat -tlunp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 24789/java tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3260/sshd tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 24789/java udp 0 0 0.0.0.0:12130 0.0.0.0:* 728/dhclient udp 0 0 0.0.0.0:68 0.0.0.0:* 728/dhclient udp 0 0 172.31.149.53:123 0.0.0.0:* 825/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 825/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 825/ntpd udp6 0 0 :::17706 :::* 728/dhclient udp6 0 0 :::123 :::* 825/ntpd [root@sdfadfasd2123 xwhapi]#
配置定时任务:(以下显示的是每天凌晨 4 点执行)
crontab -e
0 4 * * * /usr/local/xwhapi/jiaoben/jiaoben.sh >/dev/null 2>&1
启动定时任务:
service crond start
注意赋予脚本执行权限:
chmod是权限管理命令change the permissions mode of a file的缩写。。
u代表所有者,x代表执行权限。 + 表示增加权限。
chmod u+x file.sh 就表示对当前目录下的file.sh文件的所有者增加可执行权限。
浙公网安备 33010602011771号