Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

sshpass not working in shell script while giving username and password in varibales

I am using this below script and i am getting this error -p: command not found

Code:

echo "Enter the server name"
read -s server
echo "Enter the Remote Username"
read -s Rem_user
echo "Enter the Remote Password"
read -s rmtpasswrd
output=sshpass -p ${rmtpasswrd} ssh ${Rem_user}@${server} -T 'df -h;'
echo $output 

Please let me know what is the error in the script.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You need to use a command substitution to run ssh and capture its output.

output=$(ssh "${Rem_user}@${server}" 'df -h')

There is no reason to use sshpass if you are going to prompt the user for a password. ssh already does that (and more securely than you can).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading