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

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 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 HW5: text processing; scripting 1. Write a Linux command to rewrite the /var/passwd file...
Ubuntu Linux HW5: text processing; scripting 1. Write a Linux command to rewrite the /var/passwd file to have a tab for each delimiter ':'. Hint: use tr 2. Write a Linux command to extract the user names and sort them. Hint: use cut 3. Write a for loop to to display a time table, e.g., 17 x 1 = 17; 17 x 2 = 34; etc., as follows: 17 x 1 = 17 17 x 2 = 34 17 x...
This program is a simple version of the linux shell using execvp by forking using C...
This program is a simple version of the linux shell using execvp by forking using C Currently this program of the shell assumes user enters no spaces before and no extra spaces between strings. Using exec, an executable binary file (eg: a.out) can be converted into a process. An example of using exec is implementing a shell program or a command interpreter. A shell program takes user commands and executes them. int execvp(const char *file, char *const argv[]); Same as...
In shell script what is the reason this statement is not working? x=7 y=13 while [...
In shell script what is the reason this statement is not working? x=7 y=13 while [ $x -le $y ] do echo $x x=x+2 done why on while statement it has error? 2.x=7 y=13 while [$x \< $y ] do echo $x let x=x+2 done what does it mean \< ? and give me the reason how this statement works
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT