System Administration Assignment
- Details
- Category: Level 1, System Administration (Linux BASH Scrip)
- Published: Sunday, 26 August 2018 15:36
- Hits: 18488
Istvan Franko
Level 1 BSc
Lecturer:
Michael Lawrence
Task A – Customise your Virtual Machine
Task B – Write a Text Based Menu Driven BASH Script
· Show the type of kernel (uname)
· Using Tar to create and access to archive file (tar)
Task C – Produce a Screencast of your BASH Terminal
· Get the current directory structure in tree like format (tree)
· Display the file system disk space usage (df)
You are a Senior System Administrator, working for Teachem Bash Ltd, a bespoke software development company based in the North East of England.
The company director, Mick McMackem, would like you to investigate the possibility of moving the organisation's Microsoft Windows systems over to a Linux based environment.
Mr. McMackem would like you to investigate many of the alternative features that are available in Linux via the creation of a virtual machine. He would also like you to use the VMware software application to showcase and demonstrate your final system to him.
Task A – Customise your Virtual Machine
Log in to your virtual machine using the default user name and password.
Once you have successfully logged in to the system, create your own 'administrator' user account.
You MUST perform the rest of the requirements for this assignment using your new account.
User: *******
Password: ********
Add user: sudo /usr/sbin/useradd –d /home/******** –m *******
Set password: passwd *********
Add user to admin group: sudo adduser ******* admin
Add user to sudo group: sudo adduser ******* sudo
Create a new alias command called 'cet103demo' which displays the contents of the bash 'history list' one page at a time. Make sure your new alias is automatically loaded when your lubuntu virtual machine starts up.
Create alias: alias cet103demo='history | less'
For automatically loading we need add this command to .bashrc file: gedit ~/.bashrc
Customise the terminal environment by changing the default colours of the terminal prompt and any text you type after the prompt.
Prompt to green colour: export PS1="\e[0;32m[\u@\h \W]\$ \e[m "
On lubuntu we can edit the text colours with LXTerminal Edit/Prefrences function.
Use the vi text editor to create a new BASH script called 'vi_demo.sh'. This new file must be saved to your desktop and should contain the following message:
“The vi text editor is very user friendly!”
On the day of your system demonstration, you will be expected to successfully run this script.
[esc] enter to command mode
:q quit
:i insert before cursor
I insert text to cursor position
:w save
R keep replacing character until [esc]
#!/bin/bash
# vi_demo.sh
echo " The vi text editor is very user friendly!"
Once your script has run, the assessor will then ask you to use the vi editor to modify your original code in some way. You will then need to prove that the new modifications have worked by running your script again.
Setting this file attribute: chmod 755 vi_demo.sh
Run this script: ./vi_demo.sh
Task B – Write a Text Based Menu Driven BASH Script
Call your bash script TaskB.sh and save it to the desktop of your virtual machine.
Ensure your TaskB.sh Menu provides the following functionality:
*you can find the whole code in the appendix!
Create a new file called Option1.txt on your desktop. This file should contain the contents of your 'home' directory. Make sure that your output is:
* Sorted alphabetically by entry extension.
* Includes any hidden files and folders.
* Shows all of the file sizes in human readable format.
#function for first option
function CreateOption1 {
clear
ls -Xahog /home/bg47bp > /home/bg47bp/Desktop/Option1.txt
echo "The Option1.txt file saved to your desktop"
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
Calculate and display the number of lines and words that are contained in the TaskB.sh file, then output the actual contents of TaskB.sh in the terminal.
#function for second option
function CalculateLinesWords {
clear
echo "Lines number: "
wc -l TaskB.sh
echo
echo "Words number: "
wc -w TaskB.sh
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to show TaskB.sh file contetnts"
clear
more TaskB.sh
echo
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
Display the top ten lines of the .profile file then output the file type of the .xscreensaver file. Both of these files can be found in your home directory.
#function for third option
function DisplayTop10 {
clear
echo "The top ten lines of the .profile file"
echo
head /home/bg47bp/.profile
echo
echo "The .xscreensaver file type is:"
file /home/bg47bp/.xscreensaver
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
Perform a case-insensitive search on the /etc/apt/sources.list file by retrieving and displaying those lines which contain the word 'not'.
#function for fourth option
function SearchNotWord {
clear
echo "Case-insensitive search 'not' word in /etc/apt/sources.list file"
echo
grep -iw --colour=always "not" /etc/apt/sources.list
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
Ask the user if they want to exit from your menu, if they select ‘y’ then the application must close, if they select ‘n’ they must be returned to the original menu. This option MUST also inform the user about any incorrect values they enter.
#exit from bash with validitation
function exitfrombash {
echo
echo "EXIT"
echo "---------------------------"
echo "Do you want to EXIT? $(tput setaf 1)(y/n)$(tput sgr 0) "
echo
read E
if [ "$E" == n ] || [ "$E" == y ]; then
case $E in
y)ExitYes;;
n)ExitNo;;
esac
else
clear
echo "Invalid value. Please try again"
echo
exitfrombash
fi
}
function ExitYes {
clear
exit
}
function ExitNo {
clear
menudisplay
}
Extra 'Advanced' Features:
Create your own 'advanced' system administration options and incorporate the appropriate BASH code in your menu.
· Show the type of kernel (uname)
· Using Tar to create and access to archive file (tar)
*The whole Advanced Menu code in the appendix!
Task C – Produce a Screencast of your BASH Terminal
* You MUST use the ‘shelr’ screen recording software to produce your screencast.
* Your screencast MUST last no longer than 3 minutes and also demonstrate the following functionality:
*I created a menu to TaskC as well. You can find the whole code in the appendix!
Record: shelr record
Replay: shelr play last or shelr play [id]
List: shelr list
Exit: exit or Ctrl+d
Home directory: cd ~/.local/share/shelr
Delete: rm –r [id] (we need use –r ( recursive mode) because the id is a folder)
Send a list of all the ‘currently running processes’ to a file called allprocesses.txt. Save this file to the desktop then display its contents in the terminal window. Make sure that each line of your output is numbered and ends with a dollar sign.
Send a list of all Currently Running Processes to a file called allprocesses.txt and save to desktop. All line ends got a dollar sign.
ps -eo "%c$" > /home/bg47bp/Desktop/allprocesses.txt
Display this file contents with numbered lines.
less -N allprocesses.txt
Display a message containing your name, your course of study and the current year. Ensure that each part of the message is displayed on a separate line.
echo -e "Istvan Franko\nComputing\n2014"
Use the secure-delete package to erase the allprocesses.txt file that you created during part C1.
Make sure that your code uses the following settings:
* Lessen the security
* Enable 'recursive' mode
* Enable 'verbose' mode
srm -rlv allprocesses.txt
C4.
Include any 'advanced' BASH scripting commands that you think a system administrator may use.
*Please Note: all commands used for this task MUST be different to those used during Task A and Task B.
· Get the current directory structure in tree like format (tree)
· Display the file system disk space usage (df)
*The whole Advanced Menu code in the appendix!
References
Blum R. and Bresnahan C. (2011) Linux Command Line and Shell Scripting Bible -Second Edition. Indianapolis: Wiley Publishing Inc.
Nemeth E. , Snyder G. , R.Hein R. , Whaley B. (2011) Unix and Linux System Administration Handbook -Fourth Edition. Michigan US: Pearson Education Inc.
OsborneMcGraw-Hill. (1996) Linux. (“Könnyen is lehet” series) Budapest: Panem KFT.
#!/bin/bash
# TaskB.sh menu
#Main Menu function
function menudisplay {
echo "My TaskB Menu"
echo "-------------"
echo
echo "$(tput setaf 1)1$(tput sgr 0), Create Option1.txt which contain the contents of 'home' directory"
echo
echo "$(tput setaf 1)2$(tput sgr 0), Display the number of lines and words in TaskB.sh file and show the contents"
echo
echo "$(tput setaf 1)3$(tput sgr 0), Display top 10 lines of the .profile file and the file type of the .xscreensaver file"
echo
echo "$(tput setaf 1)4$(tput sgr 0), Case-insensitive search the word 'not' in sources.list file"
echo
echo "$(tput setaf 1)5$(tput sgr 0), Extra Advanced Features menu"
echo
echo "$(tput setaf 1)6$(tput sgr 0), Exit"
echo
echo "Please enter a number $(tput setaf 1)1-6$(tput sgr 0)"
#read user input
read OPTION
#statement for input validitation
if [ "$OPTION" == 1 ] || [ "$OPTION" == 2 ] || [ "$OPTION" == 3 ] || [ "$OPTION" == 4 ] || [ "$OPTION" == 5 ] || [ "$OPTION" == 6 ]; then
case $OPTION in #statement for user options
1)CreateOption1;;
2)CalculateLinesWords;;
3)DisplayTop10;;
4)SearchNotWord;;
5)AdvancedMenu;;
6)exitfrombash;;
esac
else #error message
clear
echo "Invalid option. Please try again"
echo
menudisplay
fi
}
#function for first option
function CreateOption1 {
clear
ls -Xahog /home/bg47bp > /home/bg47bp/Desktop/Option1.txt
echo "The Option1.txt file saved to your desktop"
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
#function for second option
function CalculateLinesWords {
clear
echo "Lines number: "
wc -l TaskB.sh
echo
echo "Words number: "
wc -w TaskB.sh
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to show TaskB.sh file contetnts"
clear
more TaskB.sh
echo
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
#function for third option
function DisplayTop10 {
clear
echo "The top ten lines of the .profile file"
echo
head /home/bg47bp/.profile
echo
echo "The .xscreensaver file type is:"
file /home/bg47bp/.xscreensaver
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
#function for fourth option
function SearchNotWord {
clear
echo "Case-insensitive search 'not' word in /etc/apt/sources.list file"
echo
grep -iw --colour=always "not" /etc/apt/sources.list
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
#advanced menu
function AdvancedMenu {
clear
echo "My Advanced Menu"
echo "------------------"
echo
echo "$(tput setaf 1)1$(tput sgr 0), Using Steghide "
echo
echo "$(tput setaf 1)2$(tput sgr 0), Show the type of kernel"
echo
echo "$(tput setaf 1)3$(tput sgr 0), Using Tar to create and access to archive file "
echo
echo "$(tput setaf 1)4$(tput sgr 0), Back to Main Menu"
echo
echo "Please enter a number $(tput setaf 1)1-4$(tput sgr 0)"
#read input to a variable (Option)
read OPTION
#id statement to input validation
if [ "$OPTION" == 1 ] || [ "$OPTION" == 2 ] || [ "$OPTION" == 3 ] || [ "$OPTION" == 4 ]; then
#case statement for functions
case $OPTION in
1)A1;;
2)A2;;
3)A3;;
4)A4;;
esac
else #error message
clear
echo "Invalid option. Please try again"
echo
AdvancedMenu
fi
}
#function to first option
function A1 {
clear
echo "Steghide"
echo
echo " Insert a message to a picture"
echo
echo "$(tput setaf 1)steghide embed -cf i_franko.jpg -ef hiddenmessage.txt$(tput sgr 0)"
steghide embed -cf i_franko.jpg -ef hiddenmessage.txt
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go next function"
echo
echo "Check the message file indeed hidden"
echo
echo "$(tput setaf 1)steghide info i_franko.jpg$(tput sgr 0)"
steghide info i_franko.jpg
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go next function"
echo
echo "Delete original message file"
echo
echo "$(tput setaf 1)rm hiddenmessage.txt$(tput sgr 0)"
rm hiddenmessage.txt
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go next function"
echo
echo "Extract message file from picture"
echo
echo "$(tput setaf 1)steghide extract -sf i_franko.jpg$(tput sgr 0)"
steghide extract -sf i_franko.jpg
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
AdvancedMenu
}
#function to second option
function A2 {
clear
echo "Show the type of kernel"
echo
echo "$(tput setaf 1)uname -a$(tput sgr 0)"
echo
uname -a
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
AdvancedMenu
}
#function to third option
function A3 {
clear
echo "Tar acrhives"
echo
echo " Acrhive files"
echo
echo "$(tput setaf 1)tar -cf archive.tar i_franko.jpg hiddenmessage.txt$(tput sgr 0)"
tar -cf archive.tar i_franko.jpg hiddenmessage.txt
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go next function"
echo
echo "Extract an archive file"
echo
echo "$(tput setaf 1)tar -xf archive.tar$(tput sgr 0)"
tar -xf archive.tar
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go next function"
echo
echo "Delete acrhive file"
echo
echo "$(tput setaf 1)rm archive.tar$(tput sgr 0)"
rm archive.tar
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
AdvancedMenu
}
#function to fourth option
function A4 {
clear
menudisplay
}
#exit from bash with validitation
function exitfrombash {
echo
echo "EXIT"
echo "---------------------------"
echo "Do you want to EXIT? $(tput setaf 1)(y/n)$(tput sgr 0) "
echo
read E
if [ "$E" == n ] || [ "$E" == y ]; then
case $E in
y)ExitYes;;
n)ExitNo;;
esac
else
clear
echo "Invalid value. Please try again"
echo
exitfrombash
fi
}
function ExitYes {
clear
exit
}
function ExitNo {
clear
menudisplay
}
#display Main Menu on first time
clear
menudisplay
#!/bin/bash
# TaskC.sh menu
#Main Menu function
function menudisplay {
echo "My TaskC Menu"
echo "-------------"
echo
echo "1, C1 Currently Running Processes"
echo
echo "2, C2 Display messages on separate lines"
echo
echo "3, C3 The \"allprocesses.txt \" file secure-delete "
echo
echo "4, C4 Advenced BASH scripting command Menu"
echo
echo "5, Exit"
echo
echo "Please enter a number 1-5"
#read input to a variable (Option)
read OPTION
#id statement to input validation
if [ "$OPTION" == 1 ] || [ "$OPTION" == 2 ] || [ "$OPTION" == 3 ] || [ "$OPTION" == 4 ] || [ "$OPTION" == 5 ]; then
#case statement for functions
case $OPTION in
1)C1;;
2)C2;;
3)C3;;
4)C4;;
5)exitfrombash;;
esac
else #error message
clear
echo "Invalid option. Please try again"
echo
menudisplay
fi
}
#function to first option
function C1 {
clear
echo "Send a list of all Currently Running Processes to a file called allprocesses.txt and save to desktop."
echo "All line ends got a dollar sign"
echo
echo "$(tput setaf 1)ps -eo \"%c$\" > /home/bg47bp/Desktop/allprocesses.txt$(tput sgr 0)"
ps -eo "%c$" > /home/bg47bp/Desktop/allprocesses.txt
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go next function"
echo
echo "Display this file contents with numbered lines."
echo
echo "$(tput setaf 1)less -N allprocesses.txt$(tput sgr 0)"
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go next function"
less -N allprocesses.txt
clear
menudisplay
}
#function to second option
function C2 {
clear
echo "Display my name, course of study and current year on separate lines "
echo
echo "$(tput setaf 1)echo -e \"Istvan Franko\nComputing\n2014\"$(tput sgr 0)"
echo
echo -e "Istvan Franko\nComputing\n2014"
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
#function to third option
function C3 {
clear
echo "The \"allprocesses.txt \" file secure-delete with"
echo -e "\t*Lessen the security"
echo -e "\t*Enable recursive mode"
echo -e "\t*Enable verbose mode"
echo
echo "$(tput setaf 1)srm -rlv allprocesses.txt$(tput sgr 0)"
echo
srm -rlv allprocesses.txt
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
menudisplay
}
#function to advanced menu option
function C4 {
clear
AdvancedMenu
}
#advanced menu
function AdvancedMenu {
echo "My Advanced Menu"
echo "------------------"
echo
echo "1, List Block Devices"
echo
echo "2, Get the current directory structure in tree like format"
echo
echo "3, Display the file system disk space usage "
echo
echo "4, Back to Main Menu"
echo
echo "Please enter a number 1-4"
#read input to a variable (Option)
read OPTION
#id statement to input validation
if [ "$OPTION" == 1 ] || [ "$OPTION" == 2 ] || [ "$OPTION" == 3 ] || [ "$OPTION" == 4 ]; then
#case statement for functions
case $OPTION in
1)A1;;
2)A2;;
3)A3;;
4)A4;;
esac
else #error message
clear
echo "Invalid option. Please try again"
echo
AdvancedMenu
fi
}
#function to first option
function A1 {
clear
echo "List Block Devices"
echo
echo "$(tput setaf 1)lsblk$(tput sgr 0)"
echo
lsblk
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
AdvancedMenu
}
#function to second option
function A2 {
clear
echo "Get the current directory structure in tree like format"
echo
echo "$(tput setaf 1)tree$(tput sgr 0)"
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to run this command"
tree
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
AdvancedMenu
}
#function to third option
function A3 {
clear
echo "Display the file system disk space usage"
echo
echo "$(tput setaf 1)df$(tput sgr 0)"
echo
df
echo
read -t 20 -p "Hit ENTER or wait twenty seconds to go back the menu"
clear
AdvancedMenu
}
#function to fourth option
function A4 {
clear
menudisplay
}
#exit function
function exitfrombash {
echo
echo "EXIT"
echo "---------------------------"
echo "Do you want to EXIT? (y/n) "
echo
#read input to variable
read E
#validation
if [ "$E" == n ] || [ "$E" == y ]; then
case $E in
y)ExitYes;;
n)ExitNo;;
esac
else #error message
clear
echo "Invalid value. Please try again"
echo
exitfrombash
fi
}
function ExitYes {
clear
exit
}
function ExitNo {
clear
menudisplay
}
#display main menu first time
clear
menudisplay