How to have Expect script output to file

2019-07-07 19:24发布

I need to gather some statistics from a network switch and would like to use an expect script to output the data to a file. I would like to run this script as a cron job and have the data appended to the file when it is run. Following is the working code I have so far, I just do not know how to get the output to a file. Any help is greatly appreciated.

 #!/bin/bash
 #get mac-address count
 /usr/bin/expect -f -<<EOD

 spawn ssh user@192.168.1.100
 sleep 2

 #Catch the password prompt and send supplied password
 expect {
 "*word:" {send "password\r"}
 }
 sleep 1

 #Get into enabled mode
 expect {
 "*>" {send "system-view\r"}
 }
 sleep 1

 expect {
 "*]" {send "display mac-address count\r"}
 }
 sleep 1

 expect { 
 "*]" {send "quit\r"}
 }
 sleep  1

 expect {
 "*>" {send  "quit\r"}
 }
 sleep 1

 expect eof
 EOD

0条回答
登录 后发表回答