---
title: "Shell 修改定时器"
author: "listen-raining"
date: "2016-10-13T17:08:06Z"
tags: []
categories: ["编程语言"]
slug: "shell"
draft: false
lastmod: "2016-10-13T17:08:06Z"
id: 2330390
url: "https://listen-raining.iteye.com/blog/2330390"
---

#!/bin/bash

#修改mondev用户的定时器(/var/spool/cron/mondev)

usage(){
	echo "command is not right.."
	echo "sh mondev_crontab.sh ipListFile"
	exit
}

if [ "$1" == "" ] || [ ! -r $1 ]
	then
		usage
fi


root_user="root"
root_pass="!13YXdgh"
errlog="log/crontaberror.log"

for ip in `cat $1 |awk '{print $1}'`
do
	#先清空mondev用户的定时器
	errm1=`sshpass -p $root_pass ssh -t -o StrictHostKeyChecking=no $root_user@$ip "echo >/var/spool/cron/mondev"`
	if [ "$?" == "0" ] && [ "$errm1" == "" ]
		then
			#添加定时器
			errm2=`sshpass -p $root_pass ssh -t -o StrictHostKeyChecking=no $root_user@$ip "echo '0 */24 * * * /data/mondev/mondo/client/bin/magent restart' > /var/spool/cron/mondev"`
			
			if [ "$?" == "0" ] && [ "$errm2" == "" ]
				then
					echo "update crontab success"
			else
				echo "update crontab fail................."
				echo "$ip \n update crontab fail.................\n" >> $errlog
			fi
			
	else
		echo "clearn /var/spool/cron/mondev has error....."
		echo "$ip \n clearn /var/spool/cron/mondev has error..... \n " >> $errlog
	fi
	
	sleep 1
	
done



                   








@dianxinguangchang.43F.zhongshanerlu.yuexiuqu.guangzhoushi.guangdongsheng

2016年10月13日 星期四 17时10分