Im a UNIX newbie so please excuse the little knowledge I have, Im trying to learn. I created a script that logs into multiple servers, gets data and saves it on the local server.
The script looks like this..
#!/opt/local/bin/expect
# Set username/password to initially login to switch.
set login_user "username"
set timeout -1
proc getpass pwprompt {
set oldmode [stty -echo -raw]
send_user "$pwprompt"
set timeout -1
expect_user -re "(.*)\n"
send_user "\n"
eval stty $oldmode
return $expect_out(1,string)
}
exec echo "From: EP Line Count" > myoutputfilenew
exec echo "To: test@tester.com" >>myoutputfilenew
exec echo "Subject: EP counts per HIQ" >>myoutputfilenew
exec echo "EP LIST" >> myoutputfilenew
exec echo "" >> myoutputfilenew
exec echo "Here are the EP line counts for each HIQ." >> myoutputfilenew
exec echo " " >> myoutputfilenew
set login_pass [getpass "whats your password? "]
set timeout 1
set get_count "wc -l NEW_FILE"
set hostfile [open "EPCHECK_ALL.hosts" "r"]
while {[gets $hostfile line] != -1} {
puts "My current host file is $line."
sleep 1
spawn ssh $login_user@$line
expect {
"password:" {send "$login_pass\r"}
"(yes/no)?" {send "yes\r"; exp_continue}
}
expect "$"
send "./scriptFindEDP >FILENAME\r"
expect "$"
send "cat FILENAME | sed 's/ //g' | sed '/^$/d' | grep -v 'EP' | grep -v '*' | sort > NEW_FILE\r"
expect "$"
send "$get_count\r"
expect "$get_count\r"
expect -re "(.*)\r"
puts "The number of lines with COS is$expect_out(1,string)"
exec echo "Total lines with EP COS for $line is $expect_out(1,string)" >> myoutputfilenew
# set result $expect_out(buffer)
# set result $expect_out(1,string)
# puts "The answer is $result."
expect "$"
send "exit\r"
send "exit\r"
}
close $hostfile
The output does this....
Total lines with EP COS for switchone is
47 NEW_FILE
How do I get the "47 NEW_FILE" to stay on the same line as the rest?
Also, I want to make it e mail me the outputfile when its all said and done, Im do not know how to set that automatically.
Any and all help will be greatly appreciated. 