如何将 sshpass 命令放入 bash 脚本中? [英] How to put sshpass command inside a bash script?
问题描述
我正在尝试在 bash 脚本中运行 sshpass 命令,但它不起作用.
I am trying to run a sshpass command inside a bash script but it isn't working.
如果我从终端运行相同的命令,它可以正常工作,但在 bash 脚本中运行它就不行.
If I run the same command from the terminal it works fine but running it in a bash script it doesn't.
#! /bin/bash
sshpass -p 'password' ssh user@host command
我知道安全问题,但现在不重要.
I am aware of the security issues but its not important now.
有人可以帮忙吗?我是不是遗漏了什么.
Can someone help? Am I missing something.
谢谢
推荐答案
在命令行中执行 which sshpass
以获取 sshpass
的绝对路径并将其替换为bash 脚本.
Do which sshpass
in your command line to get the absolute path to sshpass
and replace it in the bash script.
您可能也应该对您尝试运行的 command
执行相同的操作.
You should also probably do the same with the command
you are trying to run.
问题可能在于它没有找到它.
The problem might be that it is not finding it.
这篇关于如何将 sshpass 命令放入 bash 脚本中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!