Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.90 KB | None | 0 0
  1. #!/bin/bash
  2. #Bài tập kiểm tra khả năng kết nối đến các IP trong data4.txt
  3.  
  4. #Kiểm tra data04.txt có tồn tại hay không
  5. check=`ls -l | grep data04.txt`
  6. if [ "$check" == "" ]
  7. then
  8.     echo "Không tìm thấy file data04.txt";
  9.     exit 1;
  10. fi
  11.  
  12. `rm data04_result.txt &>/dev/null`
  13. successCount=0
  14. failedCount=0
  15. while read line
  16. do
  17.     status=`ping -c1 -q $line | head -4 | tail -1 | cut -d' ' -f4`
  18.     ip=$line
  19.     if [ $status -eq 1 ]
  20.     then
  21.         echo "$line -> Ping thanh cong" >> data04_result.txt
  22.         successCount=$(($successCount+1))
  23.     else
  24.         echo "$line -> Ping khong thanh cong" >> data04_result.txt
  25.         failedCount=$(($failedCount+1))
  26.     fi
  27. done < data04.txt
  28. echo "Tong so IP da kiem ra: $(($successCount+$failedCount))" >> data04_result.txt
  29. echo "So IP ping thanh cong: $(($successCount))" >> data04_result.txt
  30. echo "So IP ping khong thanh cong: $(($failedCount))" >> data04_result.txt
  31.  
  32. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement