簡體   English   中英

命令在腳本中不起作用,但在shell中起作用

[英]Command doesn't work in script, but works in shell

我正在編寫一個使用SSH“配置文件”的腳本〜/ scripts / ssh-profiled.sh

PROFILE=`cat ~/script/ssh-profiles/$1`
echo [ssh $PROFILE]
ssh $PROFILE

〜/腳本/ SSH型材/ tummi

-i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com

當我運行腳本時,它失敗了:

bart@bart-laptop:~$ script/ssh-profiled.sh tummi
[ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com]
Warning: Identity file ~/Dropbox/security/key-nopass/key-nopass.pvt not accessible: No such file or directory.
bart@example.com's password:

但這有效:

bart@bart-laptop:~$ ssh -i ~/Dropbox/security/key-nopass/key-nopass.pvt bart@example.com
Linux tummi 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux
Ubuntu 10.04.1 LTS

Welcome to the Ubuntu Server!

我的腳本中是否有錯誤/陷阱?

將第1行更改為

eval PROFILE=`cat ~/script/ssh-profiles/$1`

有關解釋請參見此處

您文件中的〜需要是完整的主目錄路徑,它不會被擴展。

我的猜測是,當以這種方式傳遞時,“〜/”沒有被解釋為預期。 嘗試使用顯式完整路徑。

.pvt文件的權限是什么? 如果只有您具有讀訪問權限,並且沒有人可以執行它,那么您的腳本可能甚至無法查看該文件。 這可能就是為什么你得到"...not accessible: No such file or directory." 信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM