Last active
March 25, 2016 12:37
-
-
Save vwainne/9f95b9a7a0199a01bf3a to your computer and use it in GitHub Desktop.
Shell Scripting assignment - System Administration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Computer System Administration-Question1(a) | |
#Script changes the default pwd and activates another script to analyze the files there. | |
#November25,2014 | |
#Question1.a :CHANGECURRENTDIRECTORYANDACTIVATEREMOTESCRIPT | |
MAIN_SCRIPT_LOCATION='/home/tacho/Documents'#storesthelocationofthescript | |
date | |
echo"Currentscript:"\"$0\""" | |
echo-e"\nPROCESSOUTCOME(S):\n------------------" | |
echo"(+)Wearedefaultedatthislocation:-";pwd#displayspresentdirectory | |
cd$MAIN_SCRIPT_LOCATION#changesthepresentworkingdirectorytothatspecified | |
echo-e"(+)Changemadetothefollowing:";pwd#showsthecurrentdirectory | |
echo -e "(+)Script Activated - | |
'printExecutables'\n>>>>>>>>------->>>>>>>------->>>>>>>\n" | |
../printExecutables #calls and activates the intended script from the "current" directory | |
#Question1.b :Returns all executable files in present working directory regardless of owner. | |
CURRENTLOCATION='/home/tacho/Documents'#storestheintendedlocationinavariable | |
date #displaysthecurrentdateandtime | |
echo "Currentscript:"\"$0\""" #displays the name of the current script | |
echo-e "\nPROCESS OUTCOME(S):\n------------------" | |
echo-e "Present working directory has been changed to:";pwd #displays present working directory | |
echo-e "The following is a list of all the executable files in this directory:\n" | |
ls -lh $CURRENTLOCATION | grep [-w]'x' > only Executables #lists all files with executable permission and stores that list in a file called only Executables | |
awk 'BEGIN { printf "%-20s %-15s %-15s %s\n","Permissions", "Owner", "Group","Filename" | |
printf"%-20s%-15s%-15s%s\n","***********","*****","*****","********" | |
{ printf "%-20s %-15s %-15s %s\n", $1, $3, $4, $9 }' onlyExecutables #displaysthecontentofthefilewithonlyspecificcolumnsandcolumnheadings | |
echo""#anewlineforreadablilitypurposes | |
# Question 2: Ashellscripttoshowallfilesinadirectoryforaspecificuser | |
#AccessandStoring | |
date #displays the current date and time | |
echo"Currentscript:"\"$0\""" #displays the name of the current script | |
echo-e"\nPROCESSOUTCOME(S):\n------------------" | |
if["$#"-eq2];then #checks whether or not two parameters were given | |
ls-l"$2"|grep-w"$1">DATAFOUND #sends a filtered list of files to a new file based on the user($1)anddirectory($2) | |
else | |
echo-e"(-)SyntaxError! Recorded"\"$#\""parameter(s).'Format:<script><user> | |
<directory>'{'_'}\n" | |
exit #If the main condition was not satisfied, this prevents the script from executing any further | |
fi #endif(ParameterTest) | |
#Displayresult(s) | |
if[-sDATAFOUND];then #verifies whether or not the file is empty | |
echo"(+)Content(s)found!{^_^}" | |
echo-e"(+)Listoffilesownedby"\"$1\""inthe"\"$2\""directory/folder:\n" | |
#The following (3) lines print content from the DATAFOUND file with specified columns and column headings using awk | |
awk 'BEGIN { printf "%-15s %-15s %-15s %s\n","Permissions", "Owner", "Group", "Filename" | |
printf "%-15s %-15s %-15s %s\n","***********", "*****", "*****","********"} | |
{printf"%-15s%-15s%-15s%s\n",$1,$3,$4,$9}'DATAFOUND | |
else | |
echo-e "(-)No file(s) exist(s) for the user,"\"$1\""in the"\"$2\""directory. {'_'}\n" | |
fi #endif(FileContentTest) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment