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
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
相关文章推荐
- [Linux] shell read命令 通过管道读取文件 [大三TJB_708]
- shell命令之read、case使用
- shell中的read命令,用户输入交互
- [Linux] shell read 命令参数 -p用法 [大三TJB_708]
- centos shell脚本编程1 正则 shell脚本结构 read命令 date命令的用法 shell中的逻辑判断 if 判断文件、目录属性 shell数组简单用法 $( ) 和${ } 和$(( )) 与 sh -n sh -x sh -v 第三十五节课
- shell中read命令
- shell--read命令
- shell学习之cat命令、文件包含、read命令、printf、函数、重定向
- [Linux] shell read命令 参数 -t -n -s记录 [大三TJB_708]
- 【Bash百宝箱】shell内建命令之read、readarray、mapfile
- 变量相关命令(env,export,set,read, array, declare)
- [Linux] shell read命令 参数 -t -n -s记录
- [shell基础]——read命令
- shell基础之二:条件判断语句if、case及read命令,
- linux的shell变量以及对set/env/export/unset/readonly命令的说明
- Linux下shell脚本中的read命令
- shell脚本中read命令的使用技巧
- shell read命令的用法
- Shell while read命令完成用户的交互输入
- 【转载】shell--read命令