创建定时任务
# crontab -l
*/1 * * * * bash /root/cpu10.sh
编写脚本
# cat cpu10.sh
echo "############start_time#####################################" >> /root/cpu10.log
echo `date` >> /root/cpu10.log
ps -eo user,pid,pcpu,pmem,args --sort=-pcpu |head -n 10 >> /root/cpu10.log
echo "#############end_time#####################################" >> /root/cpu10.log
授权脚本
ls -l cpu10.sh
-rwxr-xr-x 1 root root 278 12月 12 11:52 cpu10.sh
手工运行脚本
# sh cpu10.sh
[root@DCA ~ 2023-12-12 11:55:46]
# cat cpu10.log
验证定时任务是否成功
# tail -f cpu10.log
root 1 0.0 0.3 /usr/lib/systemd/systemd --switched-root --system --deserialize 18
root 2 0.0 0.0 [kthreadd]
root 3 0.0 0.0 [rcu_gp]
root 4 0.0 0.0 [rcu_par_gp]
root 6 0.0 0.0 [kworker/0:0H-kblockd]
root 8 0.0 0.0 [mm_percpu_wq]
root 9 0.0 0.0 [ksoftirqd/0]
root 10 0.0 0.0 [rcu_sched]
root 11 0.0 0.0 [rcu_bh]
#############end_time#####################################
文章
阅读量
获赞