如何写这个自动登录脚本 [論壇 - Ubuntu 程式設計]
正在瀏覽:
1 名遊客
如何写这个自动登录脚本 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2011/7/29 14:20 所屬群組:
已註冊使用者 等級: 18
HP : 0 / 446
![]() |
我为了自动登录vps,写了下面的脚本,
假定: vps ip :x1.x2.x3.x4 password: mypasswd #!/usr/bin/expect -f set timeout 30 spawn ssh root@x1.x2.x3.x4 expect "password:" send "mypasswd\r" expect "]*" 文件取名auto.sh 我运行 sh auto.sh 出现这样的输出: sh auto.sh auto.sh: 3: auto.sh: spawn: not found couldn't read file "password:": no such file or directory auto.sh: 5: auto.sh: send: not found couldn't read file "]*": no such file or directory spawn肯定有,请看 man expect|less -p spawn 有输出,我安装了expect apt-get install expect expect-dev 请问,如何修改我的sh脚本?
2013/1/19 9:29
|
||||||||||
![]() |
回覆: 如何写这个自动登录脚本 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() 註冊日期:
2009/12/6 10:32 所屬群組:
已註冊使用者 等級: 71
HP : 1053 / 1756
![]() |
腳本檔案 有沒有 賦予 可執行性 ?
如果沒有 它就回應 沒這個檔案
2013/1/19 9:36
|
||||||||||
![]() |
回覆: 如何写这个自动登录脚本 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
管理員
![]() ![]() 註冊日期:
2011/3/11 6:32 所屬群組:
討論區管理群 等級: 44
HP : 216 / 1084
![]() |
poloshiao 寫到: 可執行 script 程式不一定需要可執行檔案屬性 --樓主的執行方式是過的了的-- 修正:不一定
2013/1/19 10:10
|
||||||||||
![]() |
回覆: 如何写这个自动登录脚本 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() 註冊日期:
2009/12/6 10:32 所屬群組:
已註冊使用者 等級: 71
HP : 1053 / 1756
![]() |
2013/1/19 11:23
|
||||||||||
![]() |
回覆: 如何写这个自动登录脚本 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
管理員
![]() ![]() 註冊日期:
2011/3/11 6:32 所屬群組:
討論區管理群 等級: 44
HP : 216 / 1084
![]() |
luofeiyu 寫到: expect-dev 理論上不用安裝 luofeiyu 寫到: 試試看用 expect -f auto.sh 命令執行 sh auto.sh 是將 auto.sh 當作 sh 殼程式的 script 來跑,不一定相容
2013/1/19 11:40
|
||||||||||
![]() |
回覆: 如何写这个自动登录脚本 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員四級
![]() ![]() 註冊日期:
2010/8/12 15:54 所屬群組:
已註冊使用者 等級: 18
HP : 0 / 443
![]() |
如果你確定你的程式沒有大問題的話
V字龍 寫到:luofeiyu 寫到: 你的錯誤訊息產生的原因最有可能是V大說的這個狀況 你程式開頭已經 #! /usr/bin/expect 了 可以直接 chmod +x auto.sh 後 直接運作它 或是用 expect -f auto.sh 出狀況的機率比較小 另外,用 expect 我建議你用這樣的用法 spawn ssh -o "StrictHostKeyChecking no" $USER@$server set timeout 5 expect { -re "Are you sure you want to continue connecting (yes/no)?" { send "yes\r" exp_continue } -re "assword: " { send "$userpasswd\r" } } 出狀況機會比較少
2013/1/19 23:12
|
||||||||||
![]() |
您可以查看帖子.
您不可發帖.
您不可回覆.
您不可編輯自己的帖子.
您不可刪除自己的帖子.
您不可發起投票調查.
您不可在投票調查中投票.
您不可上傳附件.
您不可不經審核直接發帖.