sshpass: command not found error
you will need to install sshpass on the client server you are running your code in which is a tool that is not installed by default on most Linux distro
if you are in Ubuntu use this command
apt-get install sshpass
on centOS/redhat use this
install epel
wget
https://archives.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -ivh epel-release-6-8.noarch.rpm
install sshpass
yum --enablerepo=epel -y install sshpass
Thanks
Unable to run sshpass command in centOS
Check if your shell knows the locations of sshpass
which sshpass
If it doesnt give any output use find command to find the location of the executable:
find / -name sshpass
If you find the path, you can either use the full path of the executable:
/path/to/sshnpass
Or add the path to the PATH environmental variable, so that your shell can locate it:
export PATH=$PATH:/path/to/
Or the issue might be completely different. sshpass might not be able to find some other dependency. "ssh" client might not be installed. Or your syntax might be wrong:
using jenkins shell invokes python issues sshpass command not found
When an application can be executed in the terminal but can’t be found when invoked via a script on the same machine, most of the times the issue is the PATH
environment variable, which is where applications are searched.
The problem can be solved either
- by adjusting the
PATH
environment variable in the calling script, or - by specifying the full path when invoking the binary.
Either way, you will need to figure out where the application is located, by executing (in the terminal)
which sshpass
The result is the full path to the sshpass
exucutable. You can now use that inside your cmmd
variable in the script, or you can leave cmmd
as-is, and adjust PATH
before invoking it:
os.environ["PATH"] += os.pathsep + path_to_sshpass
Make sure to use the directory name, not the full path. That is, if the full path is /usr/local/bin/sshpass
, then path_to_sshpass
should be '/usr/local/bin'
.
bash: command not found issue ( sshpass )
try using ';'
instead of '&&'
sshpass -p 'Password' ssh admin@A.A.A.A -p 30025 "sshpass -p 'Password' ssh B.B.B.B "dpkg -s env.ns | grep -E 'Version|Package' | tr '\n' ',' |sed 's/,$/\n/' ; dpkg -s agent.ns | grep -E 'Version|Package' | tr '\n' ',' |sed 's/,$/\n/'""
sshpass is not recognized on Windows
You cant run sshpass in windows.
You can however use putty via the windows command line, to achieve the same thing.
putty -load "host" -l username -pw password
Also you can upload files via command line (with a password) using WinSCP
winscp /command "option batch abort" "option confirm off" "open sftp://user:password@example.com/" "put examplefile.txt /home/user/" "exit"
How to put sshpass command inside a bash script?
Do which sshpass
in your command line to get the absolute path to sshpass
and replace it in the bash script.
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.
Bash : `sshpass` command not working as expected with nested while loop
while read PATH;
The PATH
is a special variable. From POSIX shell manual:
PATH
A string formatted as described in the Base Definitions volume of IEEE Std 1003.1-2001, Chapter 8, Environment Variables, used to effect command interpretation; see Command Search and Execution.
...
Command Search and Execution
.... the command shall be searched for using the PATH environment variable ....
The PATH
environment variable specifies paths to search for command. Example on my system PATH
is equal to:
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/bin:/sbin:/home/kamil/bin
These are the paths my commands are in. The paths are separated by :
.
When you do while read PATH
you overwrite the PATH environment variable with some other string, so your command cannot be found.
Change the name of the variable. It is common to make exported variables upper case in shells. It is common to use lower case for variables in your script that are not exported. Also use -r
option with read so that \
backslashes are not special and specify IFS=
if you don't want to remove leading and trailing whitespaces from lines (dunno if you want to do that). Your script fixed could look like this:
#!/bin/bash
while read -r server password; do
while read -r path; do
sshpass -p "$password" scp * "$server":"$path" </dev/null
done <./paths.txt
done <./serverPass.txt
sshpass will not run provided command on Ubuntu remote host when script is sourced, but does run on windows and if run within the same script
Figured it out. I feel like I should have known this, but somehow it slipped my mind. I had to add -t -oStrictHostKeyChecking=no
on sshpass. so the command should be
sshpass -p 'password' ssh -t -oStrictHostKeyChecking=no "user@0.0.0.0" <<EOF
echo 'password' | sudo -S docker logs --tail 10 container
EOF
Hopefully someone finds this and it helps them.
Related Topics
Changing Color of Eclipse Links in Quick Fix or Eclipse Links in Preferences on Linux
How to Tell If Running in a Linux Console Versus an Ssh Session
Catching a Direct Redirect to /Dev/Tty
Access Bash Positional Parameter Through Variable
Unterminated Address Regex While Using Sed
Compile Linux Kernel (2.6) Module Including Non Kernel Headers
Where Did Wireshark/Tcpdump/Libpcap Intercept Packet Inside Linux Kernel
Qmake .Pro File Not Parsed Correctly to Generate Ld_Library_Path
Why Do We Need to Call Poll_Wait in Poll
Set Environment Variables for Non-Interactive Shell
How to Prevent Tar from Overwriting an Existing Archive
Linux Iterate Over Files in Directory
Linux: Handling a Segmentation Fault and Getting a Core Dump
How to Capture All the Commands Typed in Unix/Linux by Any User