Problem:
The timer configuration corresponding to the mondev user needs to be modified uniformly (var/spool/cron/mondev), and many hosts do not have the root user password, so the timer configuration can only be modified by the mondev user.
First, the root user directly modifies:
#echo '0 */24 * * * /data/mondev/mondo/client/bin/magent status||/data/mondev/mondo/client/bin/magent restart'>/var/ spool/cron/mondev
is then modified by the mondev user:
1.0 First generate a temporary file crontab_temp with the content of the modified timer:
0 */24 * * * /data/mondev/mondo/client/bin/magent restart
2.0 write A script file to override the mondev user's crontab, (mndify_crontab.sh):
#!/bin/bash
cronpath=/data/mondev/crontab_temp
if [ -f $cronpath ]; then
crontab $cronpath
fi
3.0 Execute mndify_crontab as the mondev user. sh script will do.
The main code is as follows: auto.sh
crontab="/root/zhangb/crontab_temp"
crontab_up="/root/zhangb/mndify_crontab.sh"
#复制文件
errm2=`sshpass -p $passwd scp -r -o StrictHostKeyChecking=no $crontab mondev@$ip:/data/mondev/`
errmp=`sshpass -p $passwd scp -r -o StrictHostKeyChecking=no $crontab_up mondev@$ip:/data/mondev/`
#执行脚本
errms=`sshpass -p $passwd ssh -t -o StrictHostKeyChecking=no mondev@$ip "sh /data/mondev/mndify_crontab.sh"`
Linux non-root users modify timer configuration
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326529357&siteId=291194637
Recommended
Ranking