您的位置:首页 > 运维架构 > Shell

shell readarray命令

2016-11-16 18:05 1536 查看
declare -a hosts 声明数组
declare -i elements i  声明2个整形变量
readarray -t删除文本结尾的换行符
crontab条目如下:

10 * * * * /root/detection_tool/sync_time.sh /root/detection_tool/time_sync_hosts

我们用来多台服务器时间同步shell scripts如下:

#!/bin/bash

declare -a hosts
declare -i elements i

readarray -t hosts < $1
elements=${#hosts[@]}

for ((i=0;i<$elements;i++)); do
echo "${hosts[${i}]}:"
ssh -i /root/xxx.key root@${hosts[${i}]} 'ntpdate -u time.rightscale.com'
ssh -i /root/xxx.key root@${hosts[${i}]} 'service ntpd restart'
done

exit 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  readarray