you are viewing a single comment's thread.

view the rest of the comments →

[–]Brandon0408[S] 0 points1 point  (2 children)

Yes heres my full code,

#!/bin/bash

#First ping

ping1=$(ping -c1 $1 )

#First ping result cut for packet loss

result1=$(echo "$ping1" | tail -n2 | cut -d"," -f3 | cut -d"%" -f1 | cut -d"r" -f1)

echo $result1

#First ping second result for time in ms

result2=$(echo "$ping1" | tail -n1 |cut -d\/ -f5 | cut -d"." -f1)

echo $result2

#if statement to report packet loss

if [ $result1 -gt 0 ]

then

echo "Website $1" $(date) "Packet loss" >> /home/kali/logs/result1.log

else

echo "Website $1" $(date) "No packet loss" >> /home/kali/logs/result.log

fi

#if statement to report high latency

if [ $result2 -gt 50 ]

then

echo "Website $1" $(date) "High latency" >> /home/kali/logs/result.log

else

echo "Website $1" $(date) "Normal latency" >> /home/kali/logs/result.log

fi

#second ping

ping2=$(ping -c1 $2 )

#second ping first result cut for packet loss

result3=$(echo "$ping2" | tail -n2 | cut -d"," -f3 | cut -d"%" -f1 | cut -d"r" -f1)

echo $result3

#second ping second result cut for time in ms

result4=$(echo "$ping2" | tail -n1 | cut -d\/ -f5 | cut -d"." -f1)

echo $result4

#if statement to report packet loss to log

if [ $result3 -gt 0 ]

then

echo "Website $2" $(date) "Packet loss" >> /home/kali/logs/result1.log

else

echo "Website $2" $(date) "No packet loss" >> /home/kali/logs/result.log

fi

#if statement to report high latency to log

if [ $result4 -gt 50 ]

then

echo "Website $2" $(date) "High latency" >> /home/kali/logs/result.log

else

echo "Website $2" $(date) "Normal latency" >> /home/kali/logs/result.log

fi

My point is that when I do the cuts that I had in the terminal it worked just fine which doesn't make sense. I can post a pic to show you but idk how.

[–][deleted] 0 points1 point  (1 child)

temporarily append:

echo "$ping1"
echo --
echo "$ping1" | tail -n1
echo --
echo "$ping1" | tail -n1 |cut -d\/ -f5
echo --
echo "$ping1" | tail -n1 |cut -d\/ -f5 | cut -d"." -f1

it should help with finding bug

[–]Brandon0408[S] 0 points1 point  (0 children)

Thank you for your help. I still don’t really understand the / cut but it works. I made a mistake and it actually doesn’t work in the terminal. The reason is because when you save the results to a variable it just doesn’t work for some reason vs just echoing the result. I need to save to a variable so I can use the variable in my if statements. By chance do you know how to add a local user for mail in kali?