0

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

这是我的 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

非常感谢您编写脚本以实现此目的的任何帮助。再一次感谢你。

4

2 回答 2

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

应该管用。

于 2013-02-14T17:49:52.330 回答
0

您可以在 bash 中使用数组:

IPADDRESSES=( 10.0.0.1 192.168.0.1 8.8.8.8 )

for IPADDRESS in ${IPADDRESSES[@]}; do
  echo ${IPADDRESS}
done
于 2013-02-14T18:12:54.043 回答