Question

Write a bash script which pings an IP address 5 times and redirects the output to...

Write a bash script which pings an IP address 5 times and redirects the output to a text file.

Use grep to search the text file and display the line "packets" to stdout.

Change the mode of the script to become an executable.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Save the below code into ping.sh file

   #!/bin/bash
   echo "Please Enter the IP Address"
   read ip
   ping -c 5 $ip > ./out.txt
   cat out.txt|grep packets

and then change the mode of the script using the below command.
   chmod +x ping.sh

Now use the command ' bash ping.sh' or './ping.sh' to run the script.

  • echo is stdout(standard output)
  • read is for stdin(standard input)
  • ping is for ping, see Man Page=> man ping
  • -c argument is to set the number of times ping is run, i.e, 5 here
  • > is to store output in a file
  • cat takes file and prints to standard output
  • | is pipe. which send the output of the command on left to program on right
  • grep matches the text.
  • chmod is to change mode and permissions.

Thank You. Please reach out for any further clarification.

Add a comment
Know the answer?
Add Answer to:
Write a bash script which pings an IP address 5 times and redirects the output to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a bash script that permanently redirects the scripts output to a file. Once the output...

    Create a bash script that permanently redirects the scripts output to a file. Once the output is permanently redirected execute 3 commands of your choosing within the script. Be sure that the script finishes by restoring output back to STDOUT

  • 1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories...

    1.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script. Do not count recursively in subdirectories. Do not call any external Linux utilities such as “ls”. 2.Write a bash script A5p1.sh to output the number of executable and non-executable files and subdirectories separately in the directory that is specified as the first command line argument to this script....

  • Duplicate IP addresses t possible for more than one ork with someone eise and set both...

    Duplicate IP addresses t possible for more than one ork with someone eise and set both computers to have the same IP address Gust change computer to have the same IP address? me of them to match the other tart a Wireshark packet capture on both computers so you can watch the actual packet raffic under these conditions a) Observe what happens when the computers with identical addresses try to ping each 5. Duplicate IP addresses a) Are the ping...

  • Write a bash script to protect a directory. Your script should notify a user of the...

    Write a bash script to protect a directory. Your script should notify a user of the following: -New file was created -Permission changes -Ownership changes -File size changes -Modification date changes Your script should have two operation modes, protect and check. Use command line flags, -p <directory> and -c <directory> to decide which mode to operate in. In protect mode, your script should create a file called .protect inside the directory you want to watch. You will use this file...

  • write the bash script Write a script compress_large_files.sh. This script accepts one or more command line...

    write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...

  • Write a shell script called GetMyStuff.sh that will provide the above information (the script must be...

    Write a shell script called GetMyStuff.sh that will provide the above information (the script must be a executable, and must work regardless of which directory it is in). Also, just saying cat MyStuff.txt is not sufficient. (1.0%) A pipeline is the combination of at least 2 commands, where the output of command1 is the input for command2. The syntax is command1 | command2 where | is the pipeline operator. Read the man pages about the ls and wc commands. Devise...

  • Write a script that will produce the output as the following runs: bash-3.00$ isNumPN 5 5...

    Write a script that will produce the output as the following runs: bash-3.00$ isNumPN 5 5 number is positive bash-3.00$ isNumPN   -45 -45 number is negative bash-3.00$ isNumPN ./isnumPN : You must give/supply one integers bash-3.00$ isNumPN 0 0 number is negative

  • LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command...

    LINUX 140U Create a file named script1.sh that contains a bash script that: Accepts NO command line arguments and does NOT use the read command. I will give you no credit if your bash script includes a read command. Also, you need to have at least one for..in loop in your code even if there may be other ways to do this problem. The script will go through a list of entries in the current directory (do not process subdirectories):...

  • Write a bash script that will: Take in three parameters. Display the name of the filename...

    Write a bash script that will: Take in three parameters. Display the name of the filename of your shelf program – such as: ”You executed the shell program $0” Display the three parameters in one line or three different lines with text telling the user what the variable is. Comment all lines as to what they do.

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT