Expect script help (newbie)

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. :confused:

i am also a noob in unix. thts why cant help u much. i am nt sure hw does expect works. was reading abt it on net while seeing the script.

bt about mailing urself ...
use mailx command at the end of ur script

cat "$myoutputfilenew" | mailx -s "$SUBJECT" "$abc@gmail.com"

abt automising this process... use crontab.

on ur home page use the below commands.

crontab -e
it will display all the entries of cron in it. accordingly set the time parameters and set

thts all i can help now

Thank you. Every bit of information will help the learning process. I will try to add the "cat "$myoutputfilenew" | mailx -s "$SUBJECT" "$abc@gmail.com" to the end of my script and see what happens....thank you again.

---------- Post updated at 12:43 PM ---------- Previous update was at 10:45 AM ----------

Stupid question.....

Where in the script would I add that e mail command?

exec echo "Total lines with EP COS for $line is $expect_out(1,string)" >> myoutputfilenew

"cat "$myoutputfilenew" | mailx -s "$SUBJECT" "$abc@gmail.com

i think this is the last updation that is happening in ur script. so u use mailx here and send it. and did u get ur cronjob done?

Ok will give it a shot. No cron yet, will wait until I have the script functioning first. Thanks again!