您的位置:首页 > 编程语言 > PHP开发

使用 expect 脚本自动化配置ntp 客户端

2013-01-18 16:04 281 查看
学习使用expect 工具。只是一个小脚本。ntp server配置好之后,有很多的ntp客户端服务器要配置,所以写了这个脚本,希望能提高效率。实现了,

自动化登录----->查找并注释指定行----->插入需要修改的配置----->启动ntp服务----->将ntp加入自启动列表----->查看服务状态----->查看和ntp服务器相差时间。

#!/usr/bin/expect

spawn /usr/bin/ssh root@10.110.10.XXX
expect  "*password:"
send    "123456\r"
expect "*]#"
send "sed -i  '/server/s/^/#/' /etc/ntp.conf\r"
send "sed -i '/fudge/s/^/#/' /etc/ntp.conf\r"
send "echo 'server 192.168.1.12 prefer'  >> /etc/ntp.conf\r"
send "ntpd -q -g\r"
send " hwclock -w\r"
send "/etc/init.d/ntp  restart\r"
send "/etc/init.d/ntp status\r"
send "chkconfig ntp on\r"
send "chkconfig -l ntp\r"
send "netstat -unl |grep 123\r"
send "ntpq -p\r"
expect "*]#"
send "exit\r"
expect eof

自动化运维道路,任重道远。
本文出自 “B612号小行星” 博客,转载请与作者联系!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: