美文网首页
ubuntu下定时任务

ubuntu下定时任务

作者: a9b854aded01 | 来源:发表于2018-11-27 09:11 被阅读0次
//如果没安装定时器,安装定时器
#!/bin/sh
cron_pid=`pgrep cron`
if [ -z "$cron_pid" ];
then
apt-get install cron
service cron start
else
 echo "[cron]"
fi
//写入另一个脚本,查找某进程PID,杀死这个进程
Pwd=`pwd`//当前脚本路径
rm -f killRemote.sh
echo "#!/bin/sh" >>killRemote.sh
echo "Remote_pid=\`ps -ef |  grep Remote_Server.dll | grep dotnet | grep -v grep | awk '{print \$2}'\`" >>killRemote.sh
echo "if [ -z \"\$Remote_pid\" ];" >>killRemote.sh
echo "then" >>killRemote.sh
echo "echo \"[no pid]\"" >>killRemote.sh
echo "else" >>killRemote.sh
echo "cur_dateTime=\"\`date +%Y-%m-%d,%H:%m:%s\`\""  >>killRemote.sh
echo "echo \"PID: \$Remote_pid \$cur_dateTime\" >> $Pwd/killlog.txt" >>killRemote.sh
echo " kill -9 \$Remote_pid" >>killRemote.sh
echo "fi" >>killRemote.sh
chmod +x killRemote.sh

//写入任务计划 每天凌晨三点执行
#echo "0 3 * * *  sh pwd/killRemote.sh" >> /var/spool/cron/root
echo "0 3 * * *  root sh $Pwd/killRemote.sh" >> /etc/crontab
#echo "*/1 * * * * root hostname >> $Pwd/killlog.txt" >> /etc/crontab
#crontab -l > conf && echo "0 3 * * * sh $Pwd/killRemote.sh" >> conf && crontab conf && rm -f conf
service cron restart

相关文章

  • ubuntu下定时任务

  • 常用的几种Linux功能介绍

    1、Ubuntu下定时任务的实现 Linux中的crond Ubuntu下crontab命令的用法 如何利用cro...

  • 《任务101 Ubuntu》

    任务地址 Ubuntu 桌面环境使用 完成时间 2016.12.4 任务要求的作业 Ubuntu之初体验 任务总结...

  • mac 下定时任务

    mac下开启定时任务有两种方式 : crontab 和 launchctl 1. crontab [通过cron...

  • 任务101 Ubuntu

    任务地址 https://bbs.excellence-girls.org/topic/207 完成时间 2016...

  • 任务101 Ubuntu

    在安装 Ubuntu 双系统(毕竟目前我还是需要在 Windows 系统下做许多事情的,因此我还不能摒弃它)和虚拟...

  • linux下定时调度任务

    目前在某公司的数据部门实习,会经常遇到scala, spark, hive, 定时执行,回调, hdfs等名词, ...

  • ubuntu16定时任务crontab

    ubuntu16定时任务crontab 缘起 最近在ubuntu16上配置了个定时任务,好长时间没配置好,后来发现...

  • Ubuntu定时执行任务

    ubuntu定时执行任务 cron是一个Linux下的后台进程,用来定期的执行一些任务。因为我用的是Ubuntu,...

  • 《任务101 Ubuntu》任务产出汇总

    任务地址 https://bbs.excellence-girls.org/topic/207/ 完成时间 201...

网友评论

      本文标题:ubuntu下定时任务

      本文链接:https://www.haomeiwen.com/subject/riwtxqtx.html