0
#!/opt/tools/unsupported/expect-5.39/bin/expect
spawn ssh -l user ip
expect_after eof {exit 0}
set timeout 10
log_file /report.txt
expect "Password:" { send "pasword\r" }
expect "$ " { send "date\r" }
expect "$ " { send "readlink /somelink\r" }
set CCM_BUILD $expect_out(buffer)
send_log "CCM: $CCM_BUILD"
expect "$ " { send "date\r" }
expect "$ " { send "exit\r" }
中的readlink的結果預計文件將是一個數字,如447,這就是我想在我的日誌文件。但我得到的是:
Password:
Last login: Tue Feb 28 09:49:42 2017 from gbplr6gn01.genband.com^M
^[[?1034h-bash-4.1$ date
Tue Feb 28 09:50:42 CST 2017
-bash-4.1$ CCM: readlink/localdisk2/jenkins/jobs/CCM/jobs/Deploy_CCM_build/builds/lastSuccessfulBuild
447
-bash-4.1$ date
Tue Feb 28 09:50:42 CST 2017
-bash-4.1$
我怎樣才能得到CCM:447?