Monday, April 24, 2017

Linux shell script

Linux shell script can be used usefully for network engineer.
For example, I need to initiate ssh connection to extreme switch to replicate some issue caused by multiple failed ssh connections. Below script can be used to execute the command periodically every 5 seconds.


[ file name : ssh ]
c=1
while [ $c -le 1001 ]
do
ssh 10.67.73.34
sleep 5
(( c++ ))
done


[ how to execute the file ]


1. change the mode of the file.
root@nms1:~$ chmod 764 ssh
root@nms1:~$ ls -al ssh
-rwxrw-r-- 1 root root 73 Apr 25 12:42 ssh*


2. execute the file, then linux system will try to connect the switch by ssh for 1000 times.
on this example, switch will deny the connection by configuration on the switch.
root@nms1:~# ./ssh
ssh_exchange_identification: Connection closed by remote host
ssh_exchange_identification: Connection closed by remote host
ssh_exchange_identification: Connection closed by remote host
ssh_exchange_identification: Connection closed by remote host




No comments:

Post a Comment