Linux uses Shell to clean up log files regularly


① Find the ProxyPoolRMIImpl process according to the process name, find the PID of the associated process, and terminate these processes.

②Delete the log file generated by the process.

③Restart the service

#!/bin/sh
webproxy_id=`ps -ef|grep ProxyPoolRMIImpl |grep -v "grep" | awk '{print $2}'`
echo $webproxy_id

for id in $webproxy_id
do
	kill -9 $id
	echo "killed $id"
done
datename='/var/webproxy/logs/'$(date +%Y-%m-%d-%H)_error'.log'
cp -f /data/webproxy/logs/error.log $datename
rm -rf /data/webproxy/logs/
rm -rf /data/webproxy/nohup.out
cd /data/webproxy/
./webproxy-start.sh  #注意,./webproxy-start.sh要引入环境变量,否则定时执行shell脚本失败。在webproxy-start.sh文件开发加入 source /etc/profile即可

Use the Linux timing task scheduler crontab to add timing tasks.

Enter in the shell window:

#: crontab -e

Add task, save and exit

0 13 * * * /data/webproxy/clean.sh

You can view task information through commands

crontab -l

View the corresponding crontab scheduler log information through the /var/log/cron file

tail -500f /var/log/cron

Guess you like

Origin blog.csdn.net/Lixuanshengchao/article/details/79865593