How to have Expect script output to file

[亡魂溺海] 提交于 2019-12-24 01:12:46

问题


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

来源:https://stackoverflow.com/questions/35075971/how-to-have-expect-script-output-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!