I’m running a script from Ubuntu 22 (WSL), and it was functioning OK until it suddenly stopped.
This script connects to remote servers and collects data via ssh using ssh-pass the code with the issue listed below.
for IP in `cat $1`
do
SERVERVER=`eval "export SSHPASS='""$(echo $password )""'";sshpass -e ssh $username@$IP -o "ConnectTimeout 3" "uname -sn"`
if [ $? == 0 ]; then
$1 – IP list
The issue is ssh connection fail due to additional characters "$" and "r"
++ sshpass -e ssh $'[email protected]' -o 'ConnectTimeout 3' 'uname -sn'
+ SERVERVER=
+ '[' 255 == 0 ']'
I tried dos2unix but still same.
Expected
++ sshpass -e ssh '[email protected]' -o 'ConnectTimeout 3' 'uname -sn'
2
Answers
I’m not familiar with
sshpass
so I can’t say anything about the validity of the command-line and options itself, but I would separate the commands and remove theeval
:The rouge
r
could be removed withtr
:The trace is pretty obvious:
So you have a carriage return character after the IP address. You get the IP address from
which means that the file named by
$1
has a carriage return. Since$1
is the first named parameter to your script, it means that this file is in error.Either pass a different (and correct) file to your script or remove the carriage returns from that file.
An alternative would be to manually remove the carriage return(s) from the IP address in your script: