Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

expect: get error status when spawn command fails

$
0
0

The below is the sample of a script which we execute daily for getting info from the server. For the last couple of days, some server data is missing from the output which is captured on the local file VS-HV-Report_2017.txt.

Is it possible to get error status when the script is executed, but its unable to connect the server? So that we have a black line or and error status instead of output?

#!/usr/bin/expect
set timeout 5
#find /path/to/files -type f -mtime +10 -delete
set date [exec date "+%d-%B-%Y"]

spawn sh -c "yes | cp -ifr .ssh/VS-HV-config .ssh/config"

spawn sh -c "> VS-HV-Report_2017.txt"

#cat ./info.py 
spawn sh -c "ssh L1n \"./info.py | sed 's/total.*//g'\" >> VS-HV-Report_2017.txt"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "passwd\r"

spawn sh -c "ssh L2n \"./info.py | sed 's/total.*//g'\" >> VS-HV-Report_2017.txt"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "passwd\r"

spawn sh -c "ssh L3n \"./info.py | sed 's/total.*//g'\" >> VS-HV-Report_2017.txt"
expect "Enter passphrase for key '/root/.ssh/id_rsa':"
send "passwd\r"
set timeout 5

#spawn sh -c "./format-VS-HV.sh > format-allinement-output.csv"
#spawn sh -c \"./format-VS-HV.sh\" > format-allinement-output.csv
exec ./format-VS-HV.sh > /root/format-allinement-output/format-allinement-output-$date.csv

Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>