Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #Bài tập kiểm tra khả năng kết nối đến các IP trong data4.txt
- #Kiểm tra data04.txt có tồn tại hay không
- check=`ls -l | grep data04.txt`
- if [ "$check" == "" ]
- then
- echo "Không tìm thấy file data04.txt";
- exit 1;
- fi
- `rm data04_result.txt &>/dev/null`
- successCount=0
- failedCount=0
- while read line
- do
- status=`ping -c1 -q $line | head -4 | tail -1 | cut -d' ' -f4`
- ip=$line
- if [ $status -eq 1 ]
- then
- echo "$line -> Ping thanh cong" >> data04_result.txt
- successCount=$(($successCount+1))
- else
- echo "$line -> Ping khong thanh cong" >> data04_result.txt
- failedCount=$(($failedCount+1))
- fi
- done < data04.txt
- echo "Tong so IP da kiem ra: $(($successCount+$failedCount))" >> data04_result.txt
- echo "So IP ping thanh cong: $(($successCount))" >> data04_result.txt
- echo "So IP ping khong thanh cong: $(($failedCount))" >> data04_result.txt
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement