Expect script with file input problems


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script with file input problems
# 1  
Old 05-29-2008
Expect script with file input problems

Hello,
I am trying to write an expect script that will ssh into a large number of Cisco routers and add some commands via the cli. The script I wrote works great for one host however I have over 350 routers that this needs to be added to. The problem is I cannot get the script to read the file of hosts. Below is the shell script and the expect script. The host file is called host_list. Any suggestions would be very much appreciated as I am about to pull my hair out. Thanks.

[~]$ cat pan_hosts
#!/usr/local/bin/bash
cat ./host_list | while read hosts; do
./pan $LINE
done

--------

[~]$ cat pan
#!/usr/local/bin/expect
set host [lindex $argv 0]
spawn ssh -l root $host
set timeout 7
expect "assword: $"
send "xxxxxxxxx\n"
expect "#"
send "config t\n"
expect "onfig)#"
send "ntp server 10.10.1.89 prefer\n"
expect "onfig)#"
send "ntp source vlan 1\n"
expect "onfig)#"
send "clock timezone CST -6\n"
expect "onfig)#"
send "clock summer-time CDT recurring\n"
expect "onfig)#"
send "access-list 88 permit 65.242.29.0 0.0.0.255\n"
expect "onfig)#"
send "access-list 88 permit 24.182.133.64 0.0.0.7\n"
expect "onfig)#"
send "snmp-server community xxxxxxxxxxxxxxxxxx rw 88\n"
expect "onfig)#"
send "exit\n"
expect "#"
send "wr\n"
expect "#"
send "exit\n"
# 2  
Old 05-29-2008
Got it working

I was able to figure out what the issue was even with my 2nd grade expect education.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problems with expect and sftp in bash

I'm having trouble with some automated sftp pulls. I'm using expect inside bash scripts and spawning SFTP. Some times the expect seems bog down. I have tried to put sleeps in my code to give everything time to work before I move on to next step but I till continue to get issues. For example when... (2 Replies)
Discussion started by: gosteen
2 Replies

2. Shell Programming and Scripting

Input in expect script

Hi, i have one problem with this script: ------------------------------- cat hostid_gathering #!/bin/bash cat /home/user1/ip_switch | while read LINE; do echo $LINE /home/user1/expect_script2 done ------------------------------ cat /home/user1/expect_script2 #!/usr/bin/expect... (6 Replies)
Discussion started by: elilmal
6 Replies

3. Shell Programming and Scripting

Problems with expect

Hi, I am writing a script to enter into a list of servers and take the backup of the cronjobs on that servers... ============================== -bash-3.00$ expect spawn.exp ssh rcdn6-vm59-33 spawn ssh servers1 /CODE]==================== -bash-3.00$ cat spawn.exp #!/usr/bin/expect eval... (1 Reply)
Discussion started by: satishkumar432
1 Replies

4. Shell Programming and Scripting

Expect script Execution Problems .. Help!!!

Hi Guys, I am writing the expect script which take input from the txt file and check whether that file is present over the Sftp or not.If yes then delete other wise check the next one.. I am able to do comparison online for single file... Please also note still i didn't try to implement... (1 Reply)
Discussion started by: hackerdilli
1 Replies

5. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

6. Shell Programming and Scripting

Problems with expect and set variables

I'm writing a script that'll send a time-stamp to my backup server. I create a file with the name of the current date, send it to my server with scp and rm the file from the local computer. Individually these commands work fine and with a set name the expect scripts also work fine. The problem... (0 Replies)
Discussion started by: Ktesh564
0 Replies

7. Shell Programming and Scripting

Expect script without user seeing output or input

I want a shell script to call an expect script but I want the expect script to run in the background so the user is not bothered with what is going on. Is there any way to do this? ---------- Post updated at 08:23 PM ---------- Previous update was at 07:39 PM ---------- got it it was ... (1 Reply)
Discussion started by: los21282
1 Replies

8. Shell Programming and Scripting

Need script to take input from file, match on it in file 2 and input data

All, I am trying to figure out a script to run in windows that will allow me to match on First column in file1 to 8th Column in File2 then Insert file1 column2 to file2 column4 then create a new file. File1: 12345 Sam 12346 Bob 12347 Bill File2:... (1 Reply)
Discussion started by: darkoth
1 Replies

9. Shell Programming and Scripting

problems installing expect utilty

Hi all, I am trying to install expect utility on RHEL 5. It is showing that we also need to install tcl also in order to run it. I have downloaded expect from Tucows Tucows Download - Download Expect 5.32.1 and tcl from SourceForge.net: Downloading ... Can someone please tell me... (5 Replies)
Discussion started by: vikas027
5 Replies

10. Shell Programming and Scripting

input from a file into an expect script ?

Hi, I have an expect script that logs into a host (via ssh) requests the hostid then exits... I am happy with that. However how can I run the same script in a kind of 'while read line' and enter lots of hosts? My knowledge is still very limited (as you will soon see) so any other ideas would... (2 Replies)
Discussion started by: starsky
2 Replies
Login or Register to Ask a Question