linux动态cronjobs

时间:2013-02-14 17:45:12

标签: bash shell dynamic

我希望继续添加更多的ips,我显然不想继续逐一添加,任何人都可以帮助我动态构建某种类型的数组,我可以每隔10分钟执行一次shell文件通过crontab?

这是我在cronjob中的内容:

*/10 * * * * scp /var/lib/asterisk/agi-bin/* 72.119.110.20:/var/lib/asterisk/agi-bin/ >/dev/null 2>&1
*/10 * * * * scp /var/lib/asterisk/agi-bin/* 72.119.110.21:/var/lib/asterisk/agi-bin/ >/dev/null 2>&1
*/10 * * * * scp /var/lib/asterisk/agi-bin/* 72.119.110.22:/var/lib/asterisk/agi-bin/ >/dev/null 2>&1

*/10 * * * * scp /etc/asterisk/extensions.conf 72.119.110.20:/etc/asterisk/extensions.conf >/dev/null 2>&1
*/10 * * * * scp /etc/asterisk/extensions.conf 72.119.110.21:/etc/asterisk/extensions.conf >/dev/null 2>&1
*/10 * * * * scp /etc/asterisk/extensions.conf 72.119.110.22:/etc/asterisk/extensions.conf >/dev/null 2>&1

*/10 * * * * scp /etc/asterisk/sip.conf 72.119.110.20:/etc/asterisk/sip.conf >/dev/null 2>&1
*/10 * * * * scp /etc/asterisk/sip.conf 72.119.110.21:/etc/asterisk/sip.conf >/dev/null 2>&1
*/10 * * * * scp /etc/asterisk/sip.conf 72.119.110.22:/etc/asterisk/sip.conf >/dev/null 2>&1

任何帮助写出一个脚本来实现这一点非常感谢。再次感谢你。

2 个答案:

答案 0 :(得分:0)

for ip in 21.119.110.{20,21,22}; do scp ... $ip:...; done

应该工作。

答案 1 :(得分:0)

你可以在bash中使用数组:

IPADDRESSES=( 10.0.0.1 192.168.0.1 8.8.8.8 )

for IPADDRESS in ${IPADDRESSES[@]}; do
  echo ${IPADDRESS}
done