墨菲定律:如果事情有变坏的可能,不管这种可能性有多小,它总会发生
误删crontab后恢复带机房名变量的cron语句
#!/bin/bash
jifang_name=`hostname|awk '{if($0~"tw") {print substr($0,1,4)}else {print substr($0,1,3)}}'`
host=`hostname`
base_file="/var/spool/cron/root"
grep -q "snmp_get.py" ${base_file}
if [ $? -eq 0 ];then
echo "cron add caiji liuliang already"
exit 1
fi
echo $host|if fgrep -q "tw";then
#{
#cat <<'EOF'
echo "* * * * * /usr/local/bandwidth_collector/snmp_get.py t"${jifang_name}" /usr/local/bandwidth_collector/monitor.log all >> /tmp/bandwidth_collect.log 2>&1">>${base_file}
echo "* * * * * /usr/local/bandwidth_collector/snmp_get.py c"${jifang_name}" /usr/local/bandwidth_collector/monitor.log all >> /tmp/bandwidth_collect.log 2>&1">>${base_file}
echo "* * * * * /usr/local/bandwidth_collector/snmp_get.py m"${jifang_name}" /usr/local/bandwidth_collector/monitor.log all >> /tmp/bandwidth_collect.log 2>&1" >>${base_file}
#EOF
#} >>${base_file}
else
echo "* * * * * /usr/local/bandwidth_collector/snmp_get.py "${jifang_name}" /usr/local/bandwidth_collector/monitor.log all >> /tmp/bandwidth_collect.log 2>&1" >>${base_file}
fi