Question: Using UNIX answer the following question please! Questions has multiple short steps. Q3. Scripting with if statement: Commands to study to answer this question: sleep,
Using UNIX answer the following question please! Questions has multiple short steps.
Q3. Scripting with if statement: Commands to study to answer this question: sleep, ps, kill, echo, cat, creating your own shell variable, if statement, and two-character shell variable $! and $?
- Exit from script, if is currently enabled; if it is not enabled, skip this item (
- Using the vi editor, create a shell script file to do the following:
- Issue sleep 1500 & command to run it as a background process.
- The two-character shell variable $! contains the process ID (pid) of the above sleep process running in the background. Display the content of the variable $!.
- Issue ps command to see that the sleep process is running.
- Store the sleep process ID (pi in a user defined (your own) shell variable
- Issue cat command with a filename that does not exist
- The two character shell variable, $? Contains the completion status of the previous cat command. Using an if statement, check the completion status of the above cat command by checking the value of $?. If cat command is successful, then echo cat command completed successfully else echo cat command failed.
- Kill the background process with pid stored in your shell variable above as the argument to kill command
- Issue ps command to see that the background process is terminated.
- Echo, the script is done using echo command
- Issue script command to capture the output of the items below
- Add execute permission to the file
- Display the attributes of the script file
- Display the content of the script file
- Run the script file by typing the name of the script file.
NOTE: You must submit both the content of the shell script file and the output generated by running the script.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
