Question

In: Computer Science

Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...

Design two shell programs working on Linux (Ubuntu)

  1. Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs.

Take a screenshot showing your shell program and its execution step.

  1. Design a shell program to remove all the shell programming files ending with sh on your home directory when a SIGINT signal is received.

Take three screenshots (The first screenshot shows one or more sh files on your home directory, and the second screenshot shows your shell program and its execution step, the third screenshot shows that sh files do not exist in your home directory after executing your shell program).

Submit your four screenshots.

Solutions

Expert Solution

First program

------------------------------

#! /bin/sh

required=2

if [ $# -eq $required ]

then

result = `expr $1 \* $2`

echo "$result"

else

echo "Wrong Input"

fi

----------------------------

In this program ,number of command line agruments is given by $# and is compared by required

then to calculate an expression expr is used as in script above  

Screenshot

Program 2

-------------------------------------

#! /bin/sh

directory = "/home/viju4076" #home directory of user

echo "The PID is $$" #required for killing the process

sigint()

{

echo "SIGINT signal received"

for filename_full in "$directory"/*

do

filename= $(basename -- "$filename_full")

extension="${filename##*.}"

if [ "$extension" = "sh" ]

then

rm "$filename_full"

fi

done

exit 0

}

trap 'sigint' INT

while true ; do

sleep 30

done

-------------------------------

In this program first we store the required path in directory variable ..Then display the PID so that signal could be send to this process by another terminal or one could use ctrl+C which also gives the same signal to the process.

Then the required work is written in sigint() function ..which gets call when signal SIGINT is received..then in function ..traverse each file get the extension and if it matches with sh then remove the file by rm command...

at last run a loop infinte times so that SIGINT can be received before ending of the script..

Screenshots


Related Solutions

Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just...
Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just logged in and have a directory called "images" in your home directory containing the following files: favicons login.png logo.png newlogo.png where "favicons is a directory and contains the files favicon.ico favicon.gif favicon.png favicon.jpg Describe the results you would expect when executing the following shell commands: i) ls images/*og* | wc -1 ii) ls -ld images/* iii) rmdir images/favicons iv) cp images/*/*png images v) rm...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
linux. If you are running UBUNTU: There may be an issue with the arrow keys working...
linux. If you are running UBUNTU: There may be an issue with the arrow keys working properly in vi on Ubuntu. When you use the arrow keys in insert mode the letters A, B, C, and D get printed instead. There are a few fixes to this problem but the main culprit is the version of vi installed on your system. Ubuntu ships with vi-light. Let’s upgrade to the full vi. Use apt to install the vim package (vim is...
In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument...
In Linux (Ubuntu), write a script to check command arguments (3 arguments maximum). Display the argument one by one. If there is no argument provided, remind users about the mistake. If there is an easy way to use a loop to get all arguments, use it? a. Display the source code in an editor (#4-1) b. Execute your script in the terminal, and display the command and the result (#4-2)
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
UNIX/LINUX LAB (1) Review the sample shell program (tryShell.c), and compile/run the program (tryShell) with the...
UNIX/LINUX LAB (1) Review the sample shell program (tryShell.c), and compile/run the program (tryShell) with the following commands, and at the end, use CTRL+C to terminate the program: ls ls -l tryShell* date whoami hostname uname -a ctrl+C    (2) Run the program (tryShell) with "time -p" with a few commands: time -p ./tryShell (3) Edit the program (tryShell.c) so that it will exit (terminate the program) when the input command string is "exit" try shell.c code at bottom //////////// #include...
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize...
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize how many good answers and how many wrong answers were provided). The script should use up to 3 execution parameters. When executed with two parameters (let’s call it interactive mode), it should assume, that the first file contains a list of questions and the second file contains correct answers to these questions. In such execution case your script should display questions one by one...
Ubuntu Linux HW2: 1. Give one line of the Linux command to see your (your login...
Ubuntu Linux HW2: 1. Give one line of the Linux command to see your (your login ID) credential data from the passwd file. Use a pipe and grep command. 2. Give one line of the Linux command to calculate the following and save it in the hex to a file calcOut. Use bc and <<<. 3+2*4 Submit Screenshots HW3: Permission Show the result clearly after each of the following commands are executed. 1. Create a subdirectory, “HW3”. Write the Linux...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT