d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programmers Haven Is Dead, So I Ask Here Instead?
Prev12
Add Reply New Topic New Poll
Member
Posts: 105,144
Joined: Apr 25 2006
Gold: 10,475.00
Apr 18 2013 04:55pm
Quote (AbDuCt @ Apr 18 2013 06:52pm)
not really.

once you obtained enough programming logic you can see flaws and it's a quick google search most of the time to find syntax errors. i noticed that elif looked wrong so i googled elif bash and lo and behold it was missing the "then" keyword.

i hardly touch bash scripting. i mostly just write one liners to reset my nic or tor and stuff before i reset my router.



LOL my point exactly :D
Member
Posts: 9,718
Joined: Jan 29 2007
Gold: 0.00
Apr 18 2013 07:19pm
Thought i'd follow this thread up with my exam.
Thanks for the help on the if statements, i wasn't paying attention in class and hadn't noticed that each if needs a then.
heres the segment of code we had to write for our exam(or at least my version)

#!/bin/bash



#Must accept 1 commandline either --usermenu or --adminmenu else display error message.

x=0 #used to return to menu after completing task one
if [ "$#" -eq "1" ] # checking to see only 1 arguement on the script
then
if [ "$1" == "--usermenu" ] # checking to see if arguement matches
then
#generating menu options

while [ "$x" -eq "0" ] #traps user in the menu
do
echo " User Tasks"
echo " ---------"
echo " 1) Email yourself the (/etc/passwd) File"
echo
echo " 2 ) Exit"
echo
echo "Please enter a menu option:1/2"
read user #gathers user input for case
case $user in
1)
mail -s "Here is the /etc/passwd file " whoami </etc/passwd
clear #clears and re-writes menu for user
;;

2 ) let x=x+1 # sets user free from menu
clear
;;

esac
done
elif [ "$1" == "--adminmenu" ]
then
while [ "$x" -eq "0" ] #traps user in the menu
do
echo " Admin Tasks"
echo " -----------"
echo " A) Email yourself the (/etc/shadow) File"
echo
echo " B) Exit"
echo
echo "Please enter a menu option:a/b "
read admin #gathers user input for case
case $admin in
a) mail -s "Here is the /etc/shadow file" whoami < /etc/shadow
clear # clears terminal and re-writes menu options
;;
b) let x=x+1 #releases user from menu
clear
;;
esac
done
elif [ "$1" != "--adminmenu" ] && [ "$1" != "--usermenu" ] #checks if only arguement is not a valid option
then
clear
echo "Errorlevel: 200"
fi # end if statement pertaining to only 1 arguement
elif [ "$#" -lt "1" ] #checks if there is less than 1 option
then
clear
echo "errorlevel: 100"

elif [ "$#" -gt "1" ] #checks if there is more than 1 option
then
clear
echo "errorlevel: 150"

fi #end of full if statement & script.


Its got pointless comments in it as i was never very good at commenting my code.
Essentially its initialized by the command ./Final.sh with either --usermenu or --adminmenu as the argument.
It then provides a small menu of user or administrative tasks(obviously very small for the sake of it being an exam).
The only thing i didn't get on this(so either 22/24 or 23/24) to the best of my knowledge, is you needed to get the email to go to the current user using a bash command to always have current user.
Wasn't sure what command that was so i just threw whoami in. It didn't work however the email still ended up in my mail box as it returned to sender for invalid recipient.

e/ the face is case 2.

This post was edited by psrocks on Apr 18 2013 07:20pm
Member
Posts: 105,144
Joined: Apr 25 2006
Gold: 10,475.00
Apr 19 2013 12:02am

You having computer hacking exams ??? :)
Go Back To Computers & IT Topic List
Prev12
Add Reply New Topic New Poll