繁体   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