Question

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

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

ANSWER :

This is done using the exec command as you can see in the code below :

#!/bin/bash
exec 2<&1 # Save stdout in 2 as we need to restore it
exec 1>outfile # Permanent Redirection of output to 'outfile'
echo "Permanent redirection" #Command 1
ls # Command 2
pwd # Command 3
exec >&2 # Restore Output to STDOUT

The Bash Scripting is used to make a lot of manual work automatic and hence I/O redirection is important!

PLEASE LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.

THANK YOU:)

Add a comment
Know the answer?
Add Answer to:
Create a bash script that permanently redirects the scripts output to a file. Once the output...
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
  • In Putty 1. Create Bash shell script that would let a user make a copy of...

    In Putty 1. Create Bash shell script that would let a user make a copy of all the files in a directory. (3 points) 2. Create two Bash shell scripts that will perform some work (of your choice). (2*3 = 6 points) 3. Create a Bash shell script that would serve as a menu for the three scripts you have created. (1 point)

  • In the Ubuntu Terminal Create a script to copy DHCP logs to a separate file Create...

    In the Ubuntu Terminal Create a script to copy DHCP logs to a separate file Create a directory ~/scripts Create a directory ~/logs Create a script in ~/scripts, name it dhcp-activity.sh Include a comment that describes the script Print to the terminal “Copying DHCP Log Activity” Copy activity from dhclient to a file called dhclient.log in the ~/logs directory When you are finished, show the instructor: Cat dhcp-activity.sh Bash dhcp-activity.sh Cat dhclient.log

  • 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):...

  • 1. Write 4 simple shell scripts. Each question will ask you to write one or more...

    1. Write 4 simple shell scripts. Each question will ask you to write one or more command lines to solve a problem. Put the command(s) from each problem into a file named problem1.sh, problem2.sh Note that if you want your script to be interpreted by bash, each file should start with the line: #!/bin/bash and will have one (or more, as needed) commands following it. To execute each script in bash, so you can determine if it is working or...

  • In Bash Write two scripts, 'backup.sh' and 'restore.sh' which do the following: backup.sh accepts a list...

    In Bash Write two scripts, 'backup.sh' and 'restore.sh' which do the following: backup.sh accepts a list of arguments which indicate the name o the output file and a list of files that should be backed up. Will take all of the files provided oher than the first and create a tar-ball(a tarred, gzipped file) with the name provided in the first argument. restore.sh Accepts a single filename of a tar-ball created by the script above and restores the files from...

  • Create a bash script to do the following on your CentOS6 VM. To back up your...

    Create a bash script to do the following on your CentOS6 VM. To back up your home folder using tar command daily. Use gzip as the compression for tar (z option). – 10pts Hint: Make sure you exclude the tar file itself from the backup. The script should name the tar file backupYYYYMMDD.tar.gz -10 pts The script should keep the last seven days of backup files and delete backup files older than seven days. -10 pts The script should check...

  • (In Linux) 1. Create a file to write to from your script and save it as...

    (In Linux) 1. Create a file to write to from your script and save it as “.txt”. 2. Write the following information to the file that you created in Step 1: Today's date Your full name Your student ID The name of your course What directory you are in File permissions of the file that you created that allow everyone to read, write, and execute The long list of files in your current directory, providing all items and their process...

  • Programs/scripts 13. Write a bash shell script that displays the date by using the shell command...

    Programs/scripts 13. Write a bash shell script that displays the date by using the shell command date. 14. Write a command line program that takes a number and a command as arguments. Call that command that number of times. For example, if your program name is "test" test 3 dir <shows directory> dir <shows directory> dir <shows directory>

  • Hi I beed this assignment to be in a script in linux from codio. Can someone...

    Hi I beed this assignment to be in a script in linux from codio. Can someone please help me step by step thank you. Overview: In this milestone, you will demonstrate your ability to create a basic script in Linux. Review the Final Project Guidelines and Rubric document to see how this milestone will prepare you for the scripting portion of the project. You will perform this milestone in Codio in the unit called “Milestone 2: Scripting.” You will create...

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
ADVERTISEMENT