Save output to file from Expect Script - fix code problem
- or -
Post a project like this$30
- Posted:
- Proposals: 2
- Remote
- #557139
- Expired
Description
Experience Level: Entry
General information for the business: networking, routers
Description of requirements/functionality: BASH SCRIPTING, EXPECT SCRIPT
should be easy for smart guy/gal
The output of my remote command is approx 114 lines..
When I attempt to write the expect buffer to a file it only saves about 48 lines.
Basically, i find the value I want from the output of the command, then I try to write the output to a file.. and drop out of my loop. I have done some digging and its a problem that can be overcome but Im not smart enought to figure it out or dont have days to do it.
--
set values $expect_out(buffer)
set found [regexp {SR_ID} $values match fnd]
if {$found == 1} {
set i 1
while {$i < 51} {
set output [open "outputfile.txt" "a+"]
set outcome $expect_out(buffer)
puts $output $outcome
incr i
}
close $output
Specific technologies required: bash, scripting, expect
OS requirements: Linux
Extra notes: #!/usr/bin/expect -f
# this expect script file is called by a bash script that passes the IP address and the username - this works fine
# below is the bash script that calls the expect
# while read line; do
# ./test101.exp $line lorafrisbie@sprintpcs.com
# done <ipaddress.lst
# as the expect script is called it passes the IP and the username and ssh's in to the box ...
match_max 10000000
set ipaddress [lindex $argv 0]
set user [lindex $argv 1]
set timeout -1
set add1 "jjl4909@"
set add2 "10.2.113.134"
set findcmd "show subscriber full username "
set finduser $findcmd$user
spawn ssh $add1$ipaddress
set pass "pass"
# the script successfully logs in and runs the desired command which is - show subscriber username (theusername)
# if the output of the command is ' no subscriber found or anything other than what I am looking for below.. i dont care and ssh to the next box..
expect {
password: {send "$pass\r" ; exp_continue}
"# " {send $finduser\r"}
}
expect "# "
# here the problem starts.. i am running the show sub command to find the user online - when i finnaly get results for show sub user -
# i look for a particular string - 'SR_ID' - this basically tells me there is a result for show sub user, then i write the expect buffer to a file and break out of the loop
# problem is the data is only partial..
set values $expect_out(buffer)
set found [regexp {SR_ID} $values match fnd]
if {$found == 1} {
set i 1
while {$i < 51} {
set output [open "outputfile.txt" "a+"]
set outcome $expect_out(buffer)
puts $output $outcome
incr i
}
close $output
Description of requirements/functionality: BASH SCRIPTING, EXPECT SCRIPT
should be easy for smart guy/gal
The output of my remote command is approx 114 lines..
When I attempt to write the expect buffer to a file it only saves about 48 lines.
Basically, i find the value I want from the output of the command, then I try to write the output to a file.. and drop out of my loop. I have done some digging and its a problem that can be overcome but Im not smart enought to figure it out or dont have days to do it.
--
set values $expect_out(buffer)
set found [regexp {SR_ID} $values match fnd]
if {$found == 1} {
set i 1
while {$i < 51} {
set output [open "outputfile.txt" "a+"]
set outcome $expect_out(buffer)
puts $output $outcome
incr i
}
close $output
Specific technologies required: bash, scripting, expect
OS requirements: Linux
Extra notes: #!/usr/bin/expect -f
# this expect script file is called by a bash script that passes the IP address and the username - this works fine
# below is the bash script that calls the expect
# while read line; do
# ./test101.exp $line lorafrisbie@sprintpcs.com
# done <ipaddress.lst
# as the expect script is called it passes the IP and the username and ssh's in to the box ...
match_max 10000000
set ipaddress [lindex $argv 0]
set user [lindex $argv 1]
set timeout -1
set add1 "jjl4909@"
set add2 "10.2.113.134"
set findcmd "show subscriber full username "
set finduser $findcmd$user
spawn ssh $add1$ipaddress
set pass "pass"
# the script successfully logs in and runs the desired command which is - show subscriber username (theusername)
# if the output of the command is ' no subscriber found or anything other than what I am looking for below.. i dont care and ssh to the next box..
expect {
password: {send "$pass\r" ; exp_continue}
"# " {send $finduser\r"}
}
expect "# "
# here the problem starts.. i am running the show sub command to find the user online - when i finnaly get results for show sub user -
# i look for a particular string - 'SR_ID' - this basically tells me there is a result for show sub user, then i write the expect buffer to a file and break out of the loop
# problem is the data is only partial..
set values $expect_out(buffer)
set found [regexp {SR_ID} $values match fnd]
if {$found == 1} {
set i 1
while {$i < 51} {
set output [open "outputfile.txt" "a+"]
set outcome $expect_out(buffer)
puts $output $outcome
incr i
}
close $output
Jesse L.
0% (0)Projects Completed
-
Freelancers worked with
-
Projects awarded
0%
Last project
12 Dec 2024
United States
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies