Question

In: Computer Science

Please write a shell script called "myfilechecking" to determine whether a file belongs to one of...

Please write a shell script called "myfilechecking" to determine whether a file belongs to one of the following categories:

  • A directory;
  • A scrip file (readable and executable);
  • An executable file (not readable but executable, such as a.out);
  • A regular ascii file (only readable, such as a C source code file);
  • The file cannot be recognized.

  • Your script should display the corresponding information based on the category of the file;
  • The file name should be provided along with your script invocation, such as "./myfilechecking a.out" will display "a.out is an executable file."
  • If the file name is not provided by users, your script should indicate the problem and then terminate its execution.

  • Please test your script on our server to make sure it works properly and displays the information as required;

  • Please include the screenshot of your script along with the screenshot of the execution of your script below:

The screenshot of the script:

The screenshot of the execution of the script:

can you please paste the script code? Thank you

Solutions

Expert Solution

Note : As mentioned in question when we use script with a.out it should give output as "a.out is an executable file." But It will show "a.out is a script file" because in linux system it is showing as readable also as shown below

[vishalh@param-demo openmp-codes]$ ls -al a.out
-rwxrwxr-x 1 vishalh vishalh 8448 Oct 16 22:49 a.out

#!/bin/sh

if [  ! -e $1  ]; then
   echo "$1 does not exits."
else
    if [ -d $1 ]; then
     echo "$1 is a directory."
    fi

    if [ -r $1 -a -x $1 -a ! -d $1  ]; then
      echo "$1 is a script file."
    fi

    if [ ! -r $1 -a -x $1 -a ! -d $1   ]; then
     echo "$1 is a executable file."
    fi
    if [ -r $1 -a ! -d $1  -a ! -x $1  ]; then
      echo "$1 is a reular ascii file."
    fi
fi



Related Solutions

Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
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...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances...
Simple shell scripting Write a Bash shell script called strcount.sh that counts the number of occurances of a given string within a file. The scripts takes two arguments: the name of the file to check and the string to count occurances of. If the file is not found (or not readable), the script should print the error message Cannot access file and exit with code -1. Otherwise, the script should print the number of occurances of the given string and...
Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
Write a shell script that will create a new password-type file that contains user information. The...
Write a shell script that will create a new password-type file that contains user information. The file should contain information about the last five users added to the system with each line describing a single user. This information is contained in the last five lines of both the /etc/shadow and the /etc/passwd files. Specifically, you should produce a file where each line for a user contains the following fields: user name, encrypted password, and shell. The fields should be separated...
Create shell scripts, .sh file. Please include a shebang line at the top of the script...
Create shell scripts, .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that plays a simple “guess the number” game with the user. It should select a random integer in the range [0 - 10], ask the user to guess the value, and provide feedback of the form “too high”, “too low”, or “congratulations” as appropriate. After the correct value is guessed, the script should terminate.
this lab, you will write a shell script, called compare_cols.sh. This program should Read a CSV...
this lab, you will write a shell script, called compare_cols.sh. This program should Read a CSV file from standard input (STDIN). Note that in general, CSV files may contain quoted fields with embedded newlines. But for this assignment you can assume that there are no fields with embedded newlines, and therefore each new line represents a new row of the CSV file. Print a single number (integer) to standard output (STDOUT): the count of the lines in the CSV file...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
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...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh),...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh), (Arch.sh) and (Buzz.sh). The first script Main.sh must have two subroutines. The First Subroutine will display the following messages on the screen: 1-Display User login name, date and time. 2-Display System boot time. 3-Working path and Shell type 4-Display Home directory and number of files and directories in your Home. 5-Message describing briefly the requited tasks.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT