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...
Write shell script code that displays the process tree on a Linux machine. The process tree...
Write shell script code that displays the process tree on a Linux machine. The process tree should show the process identifier of each process. Those processes that have the same ancestor should be sorted by process identifier instead of by name. The process tree should show the full names of all threads, if any and available. Whenever the user identifier associated with a process differs from the user identifier associated with the parent of that process, the process tree should...
Ubuntu, Linux, MacOS use one of these systems. 1a. Create a C program that forks a...
Ubuntu, Linux, MacOS use one of these systems. 1a. Create a C program that forks a child process that executes the command ‘ls’. 1b. Extend the program you created in Problem 1a such that it takes an argument. For example, the created child process should be able to execute the command ‘ls’ with any arbitrary single argument such as ‘ls -l’, and ‘ls -a’.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT