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

How LUNCH meterpreter in Kali Linux. Complete command please. Thank you
How LUNCH meterpreter in Kali Linux. Complete command please. Thank you
Write bash shell scripts for the following problems and submit your answers a single. A )...
Write bash shell scripts for the following problems and submit your answers a single. A ) Write a linux bash shell script that reads your first and lastname as arguments and print them as shown below. In my example, I name the script as printname.sh. In the example, the two arguments follow the shell scriptname. Submit the script and output print screen. # sh ./printname.sh Abdullah Konak My first name is Abdullah My surname is Konak B ) Write a...
In Kali Linux Write a script that ask the user to enter an IP address and...
In Kali Linux Write a script that ask the user to enter an IP address and a port number, then use the provided entries from the user to perform a query on your local network and determine if the given port is open on the provide network. Need to submit solutions for both below. 1.A short report showing the functionality of your code 2. your bash script
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...
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.
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
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT