I'm trying to ping 2 different interfaces using the IPs generated by the following file.txt:
Eth1/1 ALL ETHERNET 40 192.168.40.145 Device1-1 Eth16/1 192.168.40.144
Eth1/2 ALL ETHERNET 40 192.168.41.145 Device1-2 Eth16/1 192.168.41.144
What I'm looking for is a script that allows me to first ssh into Device1-1 and ping 192.168.40.145 from source 192.168.40.144 then ssh into Device1-2 using a syntax like this:
ssh -q Device1-1 "ping 192.168.40.145 source 192.168.40.144"
ssh -q Device1-2 "ping 192.168.41.145 source 192.168.41.144"
Is there any way I can open each ssh session in a different tab?
I'm having hard time to use different string characters from a text file as variables in a new script. There has to be a easy way to do this. Any suggestions?
Much appreciated!!!
You there is an easy way to do what you just described. If you use the -t
flag in SSH you will execute the command right after logging in. Hope this helps. If not leave a comment so I can help some more. :)
ssh -t Device1-1 'ping 192.168.40.145 source 192.168.40.144'
You can probably save the output in a new file source
that.
awk '{print "ssh -q", "ping", $6, $5, "source", $NF}' file.txt > newfile.txt
The content of the newfile.txt
ssh -q ping Device1-1 192.168.40.145 source 192.168.40.144
ssh -q ping Device1-2 192.168.41.145 source 192.168.41.144
Source it.
source ./newfile.txt
Or maybe pipe the output to bash
awk '{print "ssh -q", "ping", $6, $5, "source", $NF}' file.txt | bash
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.