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

Time:01-31

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.

CodePudding user response:

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).

  • Related