Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

****HELP, I DID THIS PROJECT ALL WRONG I DONT KNOW WHERE I MESSED UP BUT I NEED HELP, I'M USING UNIX!!!! PLEASE ANSWER AND EXPLAIN

****HELP, I DID THIS PROJECT ALL WRONG I DONT KNOW WHERE I MESSED UP BUT I NEED HELP, I'M USING UNIX!!!! PLEASE ANSWER AND EXPLAIN IN DETAIL. i'M NEW TO UNIX, PLEASE HELP!!!!!!

Hint: Commands to study to answer this question: grep, wc, echo, pipe ( | ), ps, process states, and man pages for ps options

NOTE: Use man command before you start answering this question and before issuing script command to find the options to use with the ps command to find the answers in this question as well as to find the characters representing the various states of a process.

1) Issue appropriate command to display your processes, that is, processes for which you are the owner

2) Display information about your processes using long option

3) Examine the output of the previous command and with echo command, display the name (command name) and the state character for your shell process and the meaning of the state character. You have to look at the man pages for the ps command to see the meaning of the process state character before doing this question when the script is not in effect. Never issue man command when script command is in effect.

4) Using echo command, answer the process id (pid) of the shell process and the parent pid of your shell process

5) Display all the processes in the system using an appropriate option other than long option

Pipe takes the standard output of the command preceding it and feeds to standard input of the command following it. The pipe is indicated by | character between the commands as

Command1 | Command2

The grep command can be used to search for a string in one or more files. When the line with the string is found, it is displayed.

The wc command can be used to find the number of lines, number of words and number of character in a file or the input supplied to it.

Using grep and pipe do the following:

6) Issue appropriate command to display all the processes in the system and pipe the output to the grep command to display the line containing the init process.

7) Using the echo command answer the process ID (pid) of the init process.

Q2. Hint: Commands to study to answer this question: predefined shell variables,

and .profile script file, echo

SHELL, HOME, PATH, MAIL and TERM are predefined shell variables. You can use the value of a shell variable in a shell command putting $ in front of it. For example, to display the value of the HOME directory of the user, specify $HOME in the echo command like echo $HOME.

Do not give just the value of the shell variable as answer to questions given below.

8) Display the value of SHELL

9) SHELL contains the pathname of the shell program you are using. With echo command, answer what is the name of the shell program

10) Display the value of HOME

11) With echo command, answer what the HOME value stand for

12) Display the value of PATH

13) PATH contains the list of directories shell searches for the nonbuilt-in command (that is, the executable program file with name same as the command you typed). The directories in the list are separated by : character.With echo command, answer whether the list contains . (dot or period) and whether the shell searches the current working directory.

14) Display the value of MAIL

15) With echo command, answer where the system stores your emails. Indicate whether it is a directory or file.

16) Display the value of TERM

17) With echo command, answer what is the type of the terminal you are using. Note: The combination of keyboard and monitor is called a terminal. If the value of TERM is xterm, then indicate what xterm stands for. Do not give the answer as xterm.

20) The .profile file is in your login directory. It is a startup shell script file containing shell (UNIX) commands. The system executes the UNIX shell commands in this file each time you login to setup your session environment before shell displays the first shell prompt (which is $ by default). Display the content of .profile fileWith echo command specify the list of predefined shell variables in the .profile file

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 $?

21) Exit from script, if is currently enabled; if it is not enabled, skip this item (1)

22) Using the vi editor, create a shell script file to do the following:

a)Issue sleep 1500 & command to run it as a background process.

b)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 $!.

c)Issue ps command to see that the sleep process is running.

d)Store the sleep process ID (pid) in a user defined (your own) shell variable

e)Issue cat command with a filename that does not exist

f)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.

g)Kill the background process with pid stored in your shell variable above as the argument to kill command

h)Issue ps command to see that the background process is terminated.

i)Echo, the script is done using echo command

23) Issue script command to capture the output of the items below

24) Add execute permission to the file

25) Display the attributes of the script file

26) Display the content of the script file

27) 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.

Q4. Commands to study to answer this question: Read about test, shift, while loop, expr,

displaying the value of the two-character variable $1 using echo command

28) Exit from script, if is currently enabled; if it is not enabled, skip this item (1)

29) Using the vi editor, create a shell script file that displays the first 12 command line arguments. You must use a while loop, expr and shift shell commands in the script to do this question.

30) Issue script command to capture the output of the items below

31) Add execute permission to the file

32) Display the attributes of the script file

33) Display the content of the script file

34) Run the script file by typing the name of the script file and specifying 14 or more arguments

The following are helpful hints in creating the shell script file for this question:

The expr command can be used to perform arithmetic operations. For example, the value of a user defined variable, count can be incremented by 1 (that is, add 1 to count) by using the following expr command.

count=`expr $count + 1`

NOTE: (1) there should be no space before and after = when storing a value into a variable, (2) Reverse quote (`) is used and not forward quote () in the above command.

Following are the relational operators that can be used in shell scripting:

Operator Description Operator in Java and C++

-eq equal ==

-ne not equal !=

-lt less than <

-le less than or equal <=

-gt greater than >

-ge greater than or equal >=

The test command is used to evaluate the value of an expression. Value of an expression with the above relational operators will be a Boolean value, true or false. The following test command checks whether the value of the variable count is less than 12:

test $count -lt 12

Alternately, the square brackets [ ] can be used instead of the word test to evaluate an expression. For example, the above test command can be issued as follows using square brackets:

[ $count -lt 12 ]

Note, there must be space before and after [ and ], before and after lt and after 12 in the above statement.

Q5. Commands to study to answer this question: tail, head, cmp, diff, comm, uniq, touch,

umask, grep, vi, cat, ls, and echo

Two files can be compared using cmp command and diff command depending on requirements.

In order to do this question, create two files with 12 or more names with one name in each line. Make sure that some names in the two files are same and some are different. Ensure that there are few consecutive lines with identical names (duplicate lines) in each file. Also, make sure that some of the names are the same in both files.

Create these two files before issuing the script command to answer this question.

35) Display the content of each file, one at a time

36) Compare the two files using cmp command

37) Find the differences between using diff command

38) Sort first file and store the result by redirecting the output to a file as sorted

39) Sort second file and store the result by redirecting the output to another file as sorted

Two files can also be compared comm command. There are differences between cmp, diff and comm commands. Read about them and understand the differences.

40) Compare the two sorted files using comm command

41) Display ONLY the bottom 5 lines of the first file

42) Display the top few lines of the second file using the default line count, that is, without using any option in the command. Count and find how many lines it displays by default

43) Issue appropriate command to display the content of first file removing consecutive duplicate lines

44) Create the file hw2before_setting_umask using touch command

45) The umask command can be used to set or change the default file permissions to be set when a new file is created. Issue umask 600 command

46) Create the file hw2after_setting_umask using touch command

47) Display the file permissions set on hw2before_setting_umask and hw2after_setting_umask

48) Using echo command answer what permissions were removed for the owner due to the above umask command

The grep command can be used to search for a string in one or more files. When the line with the string is found, it is displayed. Check this by issuing the following grep commands.

49) Issue a grep command on hw2test1 with a name that exists in hw2test1.

50) Issue a grep command on hw2test[12] with a name that exists in both files (hw2test1 and hw2test2).

51) Issue a grep command on hw2test[12] with a name that does not exist in both files.

52) What difference you see between (16) and (17) by Observing the output of above three grep commands

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions