Linux shell scripting | LBOET | HOX FRAMEWORK
!/bin/bash
>we declare this one so the program knows our work env, in this case BASH
printf “If you want to list directories, \n You are gonna need to log in.\n”
>this one is just a print out statement that contains \n -as a NEWLINE
read -p “Username:” username
> read the user input (use a title username) and store it into username variable
while [ $username == “admin” ];
> here we are starting the while loop and refering to our username variable using dollar sign
> Remember to use ;
do
echo “oh its you admin”
done
so in this case, only if admin username is TRUE (meaning if the username is admin)
it will execute Oh its you admin
–> This will not work because while is a loop, while the admin is true it willl repeat itself
> since it is true and it isnt changing it wont stop, so we have to change that to the IF statement
read -sp “Password:” password
> reading the secret input (-sp) ,doing the same thing as for username
if [[ $password -eq “57” ]];
> if password is 57 it will execute this THEN
then
echo “Welcome, $username”
ls -al
>welcome and the username with the password 57, so not only admin. This would be
considered a mistake in security, but im doing this on purpose, you will easily figure out how to
re-form this into a valid username/password checker
else
echo “Leave this area , you no good $username”
fi
else print this echo out, so if the password isnt 57, and fi is for finishing the if loop
and some printfs for the aestetics
2nd code:
echo “Starting the checker”
printf “\n—————————–\n”
ps -a | grep -i “firefox”;
what this ps -a does is it will print out processes on your PC and -a does not cover
them all, thats why we used -e on the other ps statement (-e covers it all pretty much)
and we are in this command looking for the word firefox and its line, GREP does this
using the | we can append the grep lookup to our command
variable1=$(ps -e | grep -i “sublime_text”;)
declaring it as a variable this time to check it
if [[ $variable1 ]];
we dont have to write if variable1 == True, we can just type it like this
so jusst if SOMETHING means if its true
then
echo “Listing …$variable1”
else
echo “Sublime is off.”
fi
print “\n—————————————-\n”
and now the netstat check the same way
netstat -an | grep -i “listening”;
ALSO
Really important , you need to “chmod +x yourfile.sh” before you run it.