Question

In: Computer Science

Please write shell scripts in Kali Linux to complete the following tasks. Task A - Take...

Please write shell scripts in Kali Linux to complete the following tasks.

Task A - Take your UIN

Write a script like below that reads and displays the MIDAS ID if the following requirements are satisfied:

  1. Only lower case letter [a-z] and numeric character[0-9] are allowed

  2. MIDAS ID must between 4 to 8 digits

Test your script with the following examples:

  • Your MIDAS ID in lower case

  • Your MIDAS ID w.one upper case

  • A string less than 4 digits

  • A string longer than 8 digits

  1. Task B - Check files

    Write a script like below that gets a list of files in a directory you entered, plus your name. Your script should pop out an error if an invalid directory is entered.

    You need to test the following directories with your script:

    • /etc/systemd

    • /home

    • A directory that does not exist

Solutions

Expert Solution

The folowing ode is given below

Code:

#!/bin/bash
echo Enter your ODU MIDAS ID:
while true
do
        
        read id
        LEN=$(echo ${#id})
        if ((LEN < 4 || LEN > 8)); then
                echo "You must enter a valid midaS ID - four to eight digits only!"
                echo "Please re-enter yout MIDAS ID:"
                continue        
        fi
        if [[ "${id}" =~ [^a-z0-9] ]]; then
                echo "You must enter a valid midaS ID - four to eight digits only!"
                continue
        fi
        echo "Thank you, your MIDAS ID is: "$id
        break
done

Output Screenshot

TASK B:

#!/bin/bash
echo Enter the name of the directory you want to check:
read dir
echo Enter your name:
read name
out=$(ls $dir -1a 2> /dev/null)

if [ ${#out} == 0 ]; then
        echo Sorry, $name, $dir is not a valid directory name!
else echo "Hello $name!" && echo "Below are the contents in the requested directory: $dir" && ls $dir -1a 2> /dev/null
fi

Related Solutions

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...
Can you write the shell scripts for these C files (code in C): #include <stdio.h> #include...
Can you write the shell scripts for these C files (code in C): #include <stdio.h> #include <string.h> #include <ctype.h> int main(int argb, char *argv[]){ char ch; int upper=1; if(argb>1){ if(strcmp(argv[1],"-s")==0){ upper=1; } else if(strcmp(argv[1],"-w")==0){ upper=0; } } while((ch=(char)getchar())!=EOF){ if(upper){ printf("%c",toupper(ch)); } else{ printf("%c",tolower(ch)); } } return 0; } ======================================================== #include <stdio.h> #include <stdlib.h> int calcRange(int array[],int size){ int max=array[1]; int min=array[0]; int a=0; for(a=1;a<size;a++){ if(array[a]>max){ max=array[a]; } } for(a=1;a<size;a++){ if(array[a]<min){ min=array[a]; } } printf("%d-%d=%d\n",max,min,max-min); } int main(int arga, char **argv){...
Create shell scripts, each in its own .sh file. Please include a shebang line at the...
Create shell scripts, each in its own .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that reads sunspot data from data-shell/data/sunspot.txt and uses awk to print a list of the total number of sunspots for each year on record as well as the twelve monthly averages across the record. Note: "awk allows you to index arrays using strings, so as you traverse the data file,...
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...
Use Kali Linux Commands to show me the following: 1. Who are you? 2. Change directory...
Use Kali Linux Commands to show me the following: 1. Who are you? 2. Change directory to Downloads 3. Make a new directory 4. Make a new text file under your name (Ghada.txt) 5. Write a paragraph about Cyber security (4 to 5 sentences) >>simply open the file and write inside it 6. Change the permission to be 764 7. Open the file but with a cyber security match Show me each and every step with figure b. Enter into...
Write and run SQL statements to complete the following tasks Show the details of the employees...
Write and run SQL statements to complete the following tasks Show the details of the employees who are located in area code 901 and their manager employee number is 108. Show the details of the employees who are also mangers. Show the details of the customers whose balance is greater than 220 but less than 500. Show the details of the customers whose balance is highest. Show customer 10014’s name and the product’s descriptions which he/she purchased and the number...
Can you complete the tasks inside the sample code. All the to-do task is inside the...
Can you complete the tasks inside the sample code. All the to-do task is inside the code commented out. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> typedef struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }node; /*Task 1 - Complete the function below, newNode() will return a tree node*/ node* newNode(int key){ } /*Task 2 - Complete the function below to return the size (number of elements stored) of a binary tree*/ int size(node* root){ }...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in...
Write a shell program named HELLO2(this should be done in linux, using bash) Consider files in the current directory whose names end in 't' or 'z'. For such files only, your program should list certain LINES of the file(s). These lines are those that have at least 4 x's somewhere in the line. Note that the x's may be upper- or lower-case, and may be separated by other characters; so the following 3 lines DO match: XXxX and more things...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++...
Using Virtualbox in Debian, write a simple program (a single .cpp file) in Linux shell C++ Rules: -Use fork(), exec(), wait(), and exit() _______________________________________________________________________________________________________________________________________________ -A line of input represents a token group. -Each token group will result in the shell forking a new process and then executing the process. e.g. cat –n myfile.txt // a token group -Every token group must begin with a word that is called the command(see example above). The words immediately following a command are calledarguments(e.g....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT