文件中的命令错误,但在 shell 上运行良好
我正在尝试在脚本中运行命令,如下所示:
ssh user@host:/bin/echo > /home/path/file.log
现在,当我在命令行上运行此命令时,它工作正常,但是当放入脚本(shell 或 ruby)时,它会说:
/bin/sh: /home/path/*.log: 没有这样的文件或目录
我遗漏了什么吗?
谢谢!
更新:
奇怪的是,当我使用 putty 时,即使在 shell 上,现在也没有执行相同的操作。我已经验证路径和文件存在于正在 ssh 进入的远程计算机上。
I am trying to run a command in a script, something like this one:
ssh user@host:/bin/echo > /home/path/file.log
Now when I run this command on a command line it works fine, however when put in a script (shell or ruby ) it cribs saying:
/bin/sh: /home/path/*.log: No such file or directory
Am I missing something?
Thanks!
Update:
It's weird that same thing is not being executed now even on the shell when I use putty. I have verified that the path and file exists on remote machine which is being ssh'ed into.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要循环遍历文件。如果它可以从命令行运行,那么您的交互式 shell 就不是标准 shell。
另请注意 null 命令的使用;在许多 shell 中,您根本不需要命令。您的
echo
在每个文件的开头放置一个没有吸引力的空行。如果您尝试远程运行它,则需要引用它:
You need to loop over the files. If it works from the command line then your interactive shell is not a standard shell.
Note also the use of a null command; in many shells, you don't need a command at all. Your
echo
puts an unattractive empty line at the beginning of each file.If you are attempting to run this remotely, you will need to quote it:
当我加上引号时它工作正常:
ssh user@host:"/bin/echo > /home/path/file.log"
Its working fine when I put quotes:
ssh user@host:"/bin/echo > /home/path/file.log"