Question

In: Computer Science

i want to write bash script that generates syslog if my machine has been pinged this...

i want to write bash script that generates syslog if my machine has been pinged

this is my code, but it is not full and not work as i want

#!/bin/bash

status=`echo "$?"`

monitor=`sudo tcpdump -i eth0 icmp and icmp[icmptype]=icmp-echo -n`

if [ "$status" -eq 0 ]; then

sleep 5s

pkill -f "$0"

`echo "$monitor" | awk '{print $3}'

fi

Solutions

Expert Solution

Following command will dump the ping logs continuously to the log file. This will monitor all the interfaces attached to the machine. If you need to monitor only a specific network interface then find the interface name using networksetup -listallhardwareports and find the interface you wan to monitor

sudo tcpdump -i any icmp > log.txt

If you need only few number of output you can use below command which will output only 5 ping dumps

sudo tcpdump -i any -c5 icmp

The tcpdump command process will continue dumping the ICMP request until terminate the process. But if we are giving specific number of response then the program will stop after those requests are completed.


status=`echo "$?"`

monitor=`sudo sudo tcpdump -i any -c5 icmp`

if [ $? -eq 0 ] && [ -n "$monitor" ]; then

sleep 5s

echo "$0"

pkill -f "$0"

echo "$monitor" | awk '{print $3}'

fi

Ping command issued from another terminal

Sample output


Related Solutions

I am attempting to write a script using bash on Linux. My program must save the...
I am attempting to write a script using bash on Linux. My program must save the long list format of the parent directory to a text file. Then, it must print how many items are in this parent directory. Then, it must sort the file in reverse order and save it to a different text file. I understand that the parent directory is accessed using cd .., and I understand that a file can be written to by echoing and...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
In this assignment, you are required to write a Bash script, call it assignment2.sh. Your Bash...
In this assignment, you are required to write a Bash script, call it assignment2.sh. Your Bash script has to accept at least four input arguments, and must: 1) Print to the user a set of instructions explaining how the PATH variable can be used in Bash. 2) Save the manual of the 'awk' command in the file /tmp/help.txt. 3) Shut down your Ubuntu box at 2 o'clock tonight. 4) Store your name and your partner's name in a text file...
Fully Functional Script written in BASH In this section, you will write a fully functional script...
Fully Functional Script written in BASH In this section, you will write a fully functional script to help your manager with an important project that will build upon what you learned from your script work in Milestone Four. After you have written the script, you will execute it to generate a report for all three users (once for Bob, once for Henry, and once for Frank). You should have three unique generated reports in your ~/scripts directory (or more if...
Hello, I am using BASH. I need to write a conditional statement using grep. I want...
Hello, I am using BASH. I need to write a conditional statement using grep. I want the computer to echo true if it detects any numerical character in the first line of StrepList.txt. However, the computer tells me that "grep: [0-9]: No such file or directory" if (head -n 1 StrepList.txt | grep -o [0-9] -eq TRUE);then echo "Contains numbers" else echo "No numbers" fi
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
In bash Write a script which receives a list of parameters. If no parameters are received,...
In bash Write a script which receives a list of parameters. If no parameters are received, output an error message. Otherwise, iterate through the list and, using a case statement, test each item in the list to see if it starts with a capital letter, lower case letter, digit or other. Count each type and output at the end the total for each category (capital, lower case, digit, other).
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask...
Bash Script Write a script using while-do-done loop to convert the kilometers to miles. - Ask the user to input the number of kilometers they need to travel. - Display the number of equivalent miles for the number. Use formula, Kilometers = miles/0.62137 - Every time the loop runs, it should ask the user if they want to continue, if user enters “Y” or “y”, then the loop runs again, if user enters “N” or “n”, then stop the loop...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT