expect 背景執行後的問題 - Linux

By Kristin
at 2009-08-04T00:43
at 2009-08-04T00:43
Table of Contents
※ 引述《coolkevin (我笑他人看不穿)》之銘言:
: 請問一下 我寫了一個定時重開某一台機器的script 檔名為restart.exp
: #!/usr/local/bin/expect -f
: spawn ssh [email protected]
: set timeout 15
: expect "[email protected]'s password:"
: exec sleep 3
: send "lkksf442d\r"
: exec sleep 1
: send "reboot\r"
: exec sleep 5
: interact
: exit
: 當我直接執行的時候 $ expect -f restart.exp
: 這個script 的功能正常
: 但是當我用crontab 或 at 或 expect -f restart.exp &
: 他出現
: $ spawn ssh [email protected]
: [email protected]'s password:
: 就停住不動了
: 我把timeout, sleep 都 去掉也是一樣的結果
: 請各位先進給點指導
: 謝謝
-----------------------------------------------------------
使用crontab的時候,你可以試試在script裡 使用 log_file 這個指令
使用方法如下:
step(1)
先產生一個log檔假設是在 /home/james目錄裡
名稱為:exp.log
step(2)
修改scrip:改寫coolkevin兄的程式如下:
#!/usr/local/bin/expect -f
log_file /home/james/exp.log
spawn ssh [email protected]
expect "*password:"
send "lkksf442d\r"
send "reboot\r"
expect eof
--
: 請問一下 我寫了一個定時重開某一台機器的script 檔名為restart.exp
: #!/usr/local/bin/expect -f
: spawn ssh [email protected]
: set timeout 15
: expect "[email protected]'s password:"
: exec sleep 3
: send "lkksf442d\r"
: exec sleep 1
: send "reboot\r"
: exec sleep 5
: interact
: exit
: 當我直接執行的時候 $ expect -f restart.exp
: 這個script 的功能正常
: 但是當我用crontab 或 at 或 expect -f restart.exp &
: 他出現
: $ spawn ssh [email protected]
: [email protected]'s password:
: 就停住不動了
: 我把timeout, sleep 都 去掉也是一樣的結果
: 請各位先進給點指導
: 謝謝
-----------------------------------------------------------
使用crontab的時候,你可以試試在script裡 使用 log_file 這個指令
使用方法如下:
step(1)
先產生一個log檔假設是在 /home/james目錄裡
名稱為:exp.log
step(2)
修改scrip:改寫coolkevin兄的程式如下:
#!/usr/local/bin/expect -f
log_file /home/james/exp.log
spawn ssh [email protected]
expect "*password:"
send "lkksf442d\r"
send "reboot\r"
expect eof
--
Tags:
Linux
All Comments
Related Posts
請問SUSE 10 Sp2 Ent Server版

By Brianna
at 2009-08-03T22:13
at 2009-08-03T22:13
Ubuntu下的「暫停」功能(電源管理)

By Frederic
at 2009-08-03T21:03
at 2009-08-03T21:03
Ubuntu下的「暫停」功能(電源管理)

By Kumar
at 2009-08-03T20:46
at 2009-08-03T20:46
在USB下安裝GRUB

By Ida
at 2009-08-03T20:08
at 2009-08-03T20:08
請問SUSE 10 Sp2 Ent Server版

By Frederic
at 2009-08-03T18:11
at 2009-08-03T18:11