Bash Script
#!/bin/bash
# alive2.sh # Checks to see if hosts 192.168.1.100-192.168.1.105 are alive # Iterate through IP address for n in {100..105}; do host=192.168.1.$n ping -c2 $host &> /dev/null if [ $? = 0 ]; then echo "$host is UP" else echo "$host is DOWN" fi done What is the purpose of "if [ $? = 0 ];"? I need your kind help. ;p |
"$?" is the return code from a command. "0" means the command executed successfully.
You could also do this: Code:
if $(ping -c2 $host &> /dev/null); then (Always use [CODE] tags to make code easier to read.) |
I can't resist:
Code:
for n in {100..105} |
Quote:
|
All times are GMT -5. The time now is 10:10 PM. |