Skip to main content
formatting
Source Link
muru
  • 78.4k
  • 16
  • 214
  • 321

My target is to just validate the login is successful for list of servers in CSV file. For SSH Password, Userid and IP address, I am passing these values via CSV.

And want to capture the result of SSH Connection output after each successful SSH login.

Wrote a shell script for that but, I am seeing successful login output for only the first data set from the CSV. For rest of the servers SSH command is failing.

Script:

#!/bin/sh
INPUT=Test_data.csv
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read ip user pass
do
sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt
wait
exit
done < $INPUT
IFS=$OLDIFS

Output:

Welcome to CYBER SECURITY
Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17
SW Release Date: 2020-04-17
*r Login successful
OK
^[[?1034h10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.

Welcome to CYBER SECURITY
Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17
SW Release Date: 2020-04-17
*r Login successful
OK
^[[?1034h10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.

My target is to just validate the login is successful for list of servers in CSV file. For SSH Password, Userid and IP address, I am passing these values via CSV.

And want to capture the result of SSH Connection output after each successful SSH login.

Wrote a shell script for that but, I am seeing successful login output for only the first data set from the CSV. For rest of the servers SSH command is failing.

Script:

#!/bin/sh
INPUT=Test_data.csv
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read ip user pass
do
sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt
wait
exit
done < $INPUT
IFS=$OLDIFS

Output:

Welcome to CYBER SECURITY
Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17
SW Release Date: 2020-04-17
*r Login successful
OK
^[[?1034h10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.

My target is to just validate the login is successful for list of servers in CSV file. For SSH Password, Userid and IP address, I am passing these values via CSV.

And want to capture the result of SSH Connection output after each successful SSH login.

Wrote a shell script for that but, I am seeing successful login output for only the first data set from the CSV. For rest of the servers SSH command is failing.

Script:

#!/bin/sh
INPUT=Test_data.csv
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read ip user pass
do
sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt
wait
exit
done < $INPUT
IFS=$OLDIFS

Output:

Welcome to CYBER SECURITY
Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17
SW Release Date: 2020-04-17
*r Login successful
OK
^[[?1034h10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.

My target is to just validate the login is successful for list of servers in CSV file. For SSH Password, Userid and IP address, iI am passing these values via CSV.

And want to capture the result of SSH Connection output after each successful SSH login.

Wrote a shell script for that but  , iI am seeing successful login output for only the first data set from the CSV. For rest of the servers SSH command is failing.

Script:

#!/bin/sh INPUT=Test_data.csv OLDIFS=$IFS IFS="," [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } while read ip user pass do sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt wait exit done < $INPUT IFS=$OLDIFS

#!/bin/sh
INPUT=Test_data.csv
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read ip user pass
do
sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt
wait
exit
done < $INPUT
IFS=$OLDIFS

Output:

Welcome to CYBER SECURITY Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17 SW Release Date: 2020-04-17 *r Login successful OK ^[[?1034h10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized.

Welcome to CYBER SECURITY
Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17
SW Release Date: 2020-04-17
*r Login successful
OK
^[[?1034h10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.

My target is to just validate the login is successful for list of servers in CSV file. For SSH Password, Userid and IP address, i am passing these values via CSV.

And want to capture the result of SSH Connection output after each successful SSH login.

Wrote a shell script for that but  , i am seeing successful login output for only the first data set from the CSV. For rest of the servers SSH command is failing.

Script:

#!/bin/sh INPUT=Test_data.csv OLDIFS=$IFS IFS="," [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } while read ip user pass do sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt wait exit done < $INPUT IFS=$OLDIFS

Output:

Welcome to CYBER SECURITY Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17 SW Release Date: 2020-04-17 *r Login successful OK ^[[?1034h10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized.

My target is to just validate the login is successful for list of servers in CSV file. For SSH Password, Userid and IP address, I am passing these values via CSV.

And want to capture the result of SSH Connection output after each successful SSH login.

Wrote a shell script for that but, I am seeing successful login output for only the first data set from the CSV. For rest of the servers SSH command is failing.

Script:

#!/bin/sh
INPUT=Test_data.csv
OLDIFS=$IFS
IFS=","
[ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; }
while read ip user pass
do
sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt
wait
exit
done < $INPUT
IFS=$OLDIFS

Output:

Welcome to CYBER SECURITY
Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17
SW Release Date: 2020-04-17
*r Login successful
OK
^[[?1034h10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.
10.xx.xx.xx,admin,432584
Command not recognized.

Source Link

In Shell Script SSH connection is working only for first line data in CSV file and command failing for remaining servers

My target is to just validate the login is successful for list of servers in CSV file. For SSH Password, Userid and IP address, i am passing these values via CSV.

And want to capture the result of SSH Connection output after each successful SSH login.

Wrote a shell script for that but , i am seeing successful login output for only the first data set from the CSV. For rest of the servers SSH command is failing.

Script:

#!/bin/sh INPUT=Test_data.csv OLDIFS=$IFS IFS="," [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } while read ip user pass do sshpass -p $pass ssh -n -t -t -o "StrictHostKeyChecking no" $user@$ip >> output.txt wait exit done < $INPUT IFS=$OLDIFS

Output:

Welcome to CYBER SECURITY Cisco Codec Release ce 9.12.3 140cd8212ba 2020-04-17 SW Release Date: 2020-04-17 *r Login successful OK ^[[?1034h10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized. 10.xx.xx.xx,admin,432584 Command not recognized.