Search code examples
bashshellsshpass

bash: command not found issue ( sshpass )


I have machine A and machine B. From my local machine X , I wanted to run a bash script , Which would connect to Machine A and Then to Machine B to check package version on Machine B.

Right now , I have two or more packages installed on Machine B.

Single Package Version Check :

sshpass -p 'Password' ssh [email protected] -p 30025  "sshpass -p 'Password' ssh B.B.B.B "dpkg -s env.ns | grep -E 'Version|Package' | tr '\n' ',' |sed 's/,$/\n/'""

Result :

Package: env.ns,Version: 51.0.0n

Multiple Package Check :

sshpass -p 'Password' ssh [email protected] -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/'""

Result :

Package: env.ns,Version: 51.0.0n
-bash: dpkg: command not found

I cannot able to get the package version of the second one. Using sshpass, Can we pass multiple commands to run on host machine ?

Expected Result :

Package: env.ns,Version: 51.0.0
Package: agent.ns,Version: 51.0.0

Solution

  • try using ';' instead of '&&'

    sshpass -p 'Password' ssh [email protected] -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/'""