Reputation: 91
I want that my script pings the ip-addresses 192.168.0.45 192.168.0.17 192.168.0.108 by doing this:
bash Script.sh 45 17 108
I want to give the last numbers with bash to ping this ip-addresses.
I don't know how I have to do this. Do I have to work with a 'case' in a do while or something else??
Upvotes: 1
Views: 2573
Reputation: 22428
I want to give the last numbers with bash to ping this ip-addresses.
I presume, you want to ping the addresses simultaneously. In that case you can do this:
Script.sh:
#!/bin/bash
ping 192.168.0.$1 & ping 192.168.0.$2 & ping 192.168.0.$3 &
This will send all of the three ping commands to background where they will be executed simultaneously and print continuous output on terminal.
You can do this with a for loop too:
#!/bin/bash
for i in $*;do
ping 192.168.0.$i &
done
The for loop method can take any number of arguments
Upvotes: 1