Question

In: Computer Science

Write a C Unix shell script called showperm that accepts two command line parameters. The first...

Write a C Unix shell script called showperm that accepts two command line parameters. The first parameter should be an option flag, either r, w or x. The second parameter should be a file name. The script should indicate if the specified file access mode is turned on for the specified file, but it should display an error message if the file is not found. For example, if the user enters: showperm r thisfile the script should display “readable” or “not readable” depending on the current status of thisfile.

Solutions

Expert Solution

Please find the script to identify whether the file is not executbale/readable/writable.

Script:

#verify the arguments

if [ $# == 2 ]
then

#verify whether the first argument is r/w/x
   if [[ $1 == 'r' || $1 == 'w' || $1 == 'x' ]]
   then

#verify the file is present
       if [ -f $2 ]
       then
         if [ $1 == 'r' ]
         then

#verify the file is readable
              if [ -r $2 ]
              then
                echo "File is readable"
              else
                echo "File is unreadable"
              fi

#verify the file is writable
         elif [ $1 == 'w' ]
         then
              if [ -w $2 ]
              then
                echo "File is writable"
              else
                echo "File is unwritable"
              fi
         else

#verify the file is executable
              if [ -x $2 ]
              then
                echo "File is executable"
              else
                echo "File is not executable"
              fi
         fi
       else
        echo "File: $2 not found"
       fi
   else
      echo "usgae: $0 [r|w|x] <file-name>"
   fi
else
      echo "usgae: $0 [r|w|x] <file-name>"
fi

Output:

USER> sh showperm.sh x dcler
File: dcler not found


USER> sh showperm.sh x
usgae: showperm.sh [r|w|x] <file-name>


USER> sh showperm.sh
usgae: showperm.sh [r|w|x] <file-name>


USER> sh showperm.sh r reg1
File is readable


USER> sh showperm.sh w reg1
File is writable


USER> sh showperm.sh x reg1
File is not executable


Related Solutions

program c Write a program called filesearch that accepts two command-line arguments: A string A filename...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename If the user did not supply both arguments, the program should display an error message and exit. The program opens the given filename. Each line that contains the given string is displayed. Use the strstr function to search each line for the string. You may assume no line is longer than 255 characters. The matching lines are displayed to standard output (normally the screen).
UNIX ONLY Write a bash script that will accept a filename as a command line argument....
UNIX ONLY Write a bash script that will accept a filename as a command line argument. Your script should first check whether the filename has been passed as argument or not (hint: at least one argument has to be provided). If no argument has been provided your script should display appropriate message and exit. If a file name has been provided, your script should check if the file exists in the current directory and display the contents of the file....
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...
Write a C program that accepts a port number as a command line argument, and starts...
Write a C program that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form: GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
Write a C program that accepts a port number as a command line argument, and starts...
Write a C program that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
Write a script named countmatches that expects at least two arguments on the command line. The...
Write a script named countmatches that expects at least two arguments on the command line. The first argument is the pathname of a dna file containing a valid DNA string with no newline characters or white space characters of any kind within it. (It will be terminated with a newline character.) This dna file contains nothing but a sequence of the bases a, c, g, and t in any order. The remaining arguments are strings containing only the bases a,...
The following .py script takes a users input of search parameters on command line, creates a...
The following .py script takes a users input of search parameters on command line, creates a custom search URL, then returns top 5 result links from Google Scholar. Alter the below code so that the script opens up each found link in a separate browser window (or tabbed windows in a single browser). ——.py import requests, sys, webbrowser from bs4 import BeautifulSoup print("Searching for " + "+".join(sys.argv[1:])) myres = requests.get("https://scholar.google.com/scholar? hl=en&q=" + "+".join(sys.argv[1:]) + "&*") soup = BeautifulSoup(myres.text, "html.parser") elems...
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the...
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the files from two named directories into a new third directory. Timestamps must be preserved while copying files from one directory into another. Task Requirements Three directory names must be supplied as arguments to your script when it is executed by the user. In the beginning of your script you need to check that the first two directory names provided (e.g. dir1 and dir2) exist...
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
Write a script that represents a simple command line calculator. It will accept two numbers from...
Write a script that represents a simple command line calculator. It will accept two numbers from command line, and then display sum, difference and product of these two numbers. Provide script code and screenshot of output. Using Linux Ubuntu bash
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT