linux批量定时任务crontab(linux查看定时任务的命令)
admin2024-08-14 10:15:12Linux运维
cat 1.txt
192.168.1.100 密码
cat cron.sh
#/bin/bash
for i in `awk '{print $1}' 1.txt`
do
pass=`grep "$i" 1.txt|awk '{print $2}'`
sshpass -p "$pass" ssh -o StrictHostKeyChecking=no -p 22022 root@${i} "(crontab -l|grep -v ntpdate)|crontab" #删除原来的定时
sshpass -p "$pass" ssh -o StrictHostKeyChecking=no -p 22022 root@${i} "(crontab -l;echo '#ntpdate time')|crontab" #添加注释
sshpass -p "$pass" ssh -o StrictHostKeyChecking=no -p 22022 root@${i} "(crontab -l;echo '*/5 * * * * /usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1 && /sbin/clock -w')|crontab"
done