Expect script to verify resolv.conf

This is the final post of a thread documenting a request to update the resolv.conf file on 48 Linux servers that I am in charge of.  Keep in mind that as of right now I do not have an Admin server that I can run scripts from that have SSH keys to login without password.  Here’s is the working script that successfully patched the resolv.conf file on 48 servers.

Again here’s the starter script.

Code:
#!/bin/bash
for i in `cat hosts.txt`
do
./verifyResolve.exp $i
done

And here is the expect script.

Code:
#!/usr/bin/expect -fset password password
set hosts [lrange $argv 0 0]
set timeout  05
spawn ssh my_login$hosts
match_max 100000
expect “\#*”
send “yes\n”
expect “\#*”
send — “$password\r”
expect “\#*”
send “echo \search our.domain.info\ > /etc/resolve.conf\r”
expect “\#*”
send “echo \nameserver 165.168.1.1\ >> /etc/resolve.conf\r”
expect “\#*”
send “echo \nameserver 165.168.1.2\ >> /etc/resolve.conf\r”
expect “\#*”
send “exit\r”
expect “\#*”
send “exit\r”
expect eof

so, Basically I fixed the timeout issue, so itdoes timeout after 5 seconds and forces the next send command. Also, I decided to run script as myself and sesu to root, so the root password is not in a clear text script, and we have two root passwords on random servers.

Expect Scripts

Leave a Reply

Comment
Name*
Mail*
Website*