Expect script to read file line by line
2014-12-26 17:47
357 查看
I have an expect script which is run inside a bash script. I am trying to ssh to a jump server then from the jump server telnet to each router in a file list and run the same command. I tried many ways but down not read the router list file for some reason.
I get the following error:
wrong # args: should be "read channelId ?numBytes?" or "read ?-nonewline? channelId"
while executing
"read "
Code:
I get the following error:
wrong # args: should be "read channelId ?numBytes?" or "read ?-nonewline? channelId"
while executing
"read "
Code:
/usr/local/bin/expect << EOF ### ssh to jump server spawn /opt/SBCssh/bin/ssh test@192.168.1.254 match_max 100000 expect "*?assword:*" send "${password}\r" send "\r" expect "*$" ### read router list file into variable set fd [open hostlist r] set hosts [read $fd] close $fd ### From jump server telnet to each router in hostlist set data [split $hosts "\n"] foreach line $data { spawn telnet ${line} expect "*login: " send "${username}\r" expect "Password: " send "${password}\r" expect "*#" send "term len 0\r" expect "*#" log_file /tmp/${line}.output send "show hard\r" expect "*#" log_file send "exit\r" } ### Exit jump server set timeout 5 send "exit\r" EOF
相关文章推荐
- Shell Script Utility To Read a File Line By Line
- How to read file line by line?
- Read file line by line (Bash shell script, sed usage)
- How to read a file line by line?
- bash read file line by line
- Read in text file line by line php - newline not being detected
- Java 8 Stream – Read a file line by line
- HTTP Error 404.17 – Not Found, The requested content appears to be script and will not be served by the static file handler
- Why is using BufferedInputStream to read a file byte by byte faster than using FileInputStream
- php - Fatal error: Unable to read X bytes in file.php on line 0
- Linux tip - How to create a file and write by script?
- Bash Shell read file line by line and substring
- read file by bash shell just as getline() in c++
- how to read file by ZipFile
- Golang Read File line by line
- Step By Step guide to Read XML file in Java Using SAX Parser Example
- read line from file with bash shell script
- Open and read file line by line tcl tk
- 《How to run one script by command line in 3dsMax》
- Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file "file:/xxxWEB-INF/lib/struts.jar": org.apache.jasper.Ja