Linux Script Issue
Hello, I am trying to figure this out and really could use some help. Below is what i'm being asked to do and below that is a script I had to write the previous week, according to what I need to do it's an extension to what I've already done.I have been fighting a huge cold and I really could use help in this and look forward to a reply, my email is cf4610@gmail.com.
Ty, Chris Case – switch 2, 9 points (3 if it runs correctly, 5 if all components are included and 1 for comments) and yes we live in a partial credit world. This project is an extension of the case and switch assignment from last week. We have used all the elements of this script in prior homework projects, puzzles and/or scripts. This time around everything is a choice in a case switch script. Your shell script will use case and switch and should include the following elements: some kind of conditional test to proceed (date, verify users is logged, etc) request the user’s name (save as a variable to be used at exit) a counter that counts the number of total choices made by the user a use of the cut command (cut a field from you friends list or some other file) an option to run 5 different commands (ls, who, ping etc) and on exiting the script, echo the user’s name, user inputs (you will want to save these as varialbes and how many choices the user made). Comments MUST be included in the script! Your script should be easy for anyone to run without the need of prompting from you, the developer. Email a copy and leave an executable copy in the appropriate homework directory. Remember, by reading your comments I should be able to see exactly what your script is doing (or suppose to do). Why use comments? Comments force you to think through the scripting process. Scripting could be considered a mechanical process of converting your comments into UNIX commands. #! /bin/csh echo "Enter the month date" set a = ($<) set date = `date | cut -f 3 -d ' '` #date command cut to the date if ( $a == $date ) then #if correct date entered echo "What's your first name ?" #ask for name set b = $< #setting variable echo "Hello $b " else echo "I'm sorry that is not correct." exit 0 endif @ h = 0 # declaring the variables @ i = 0 @ j = 0 @ k = 0 @ l = 0 @ z = 0 set e = /home/fall_05/user-name/HW/11-22 #path set f = $e/menu #set variable for menu while (1) top: clear cat $f #cat menu echo -n "Enter your choice " set a = $< #set variable for choice #set z = 1 # the counter wouldn't work until I defined the variable switch ( $a ) case [aA]: #case a @ h = 1 # h is equal to 1 this sets the variable for listing inputs ls #command @ z = $z + 1 #The counter sleep 2 goto top case [bB]: @ i = 1 who @ z = $z + 1 sleep 2 goto top case [cC]: @ j = 1 last |grep $b |wc -l @ z = $z + 1 sleep 2 goto top case [dD]: @ k = 1 finger @ z = $z + 1 sleep 2 goto top case [eE]: @ l = 1 @ z = $z + 1 echo "Thank you $b for entering $z choices." echo "You ran the following commands " if ( $h == 1 ) then echo "ls " # if h is equal to 1 then echo ls and so forth following down the line if ( $i == 1 ) then echo "who " endif if ( $j == 1 ) then echo "last " endif if ( $k == 1 ) then echo "finger " endif if ( $l == 1 ) then echo "exit " endif exit 0 endsw # end switch end # end while statement #! /bin/csh #case switch echo -n "Please enter your name... " #prompts user for name set name=$< #sets user input to variable @ i = 0 #counter begins at zero @ a = 0 @ new = 0 @ f = 0 @ c = 0 @ n = 0 @ z = 0 @ dir = 0 @ address = 0 while (1) #while true echo $i #counter clear #clear screen top: #place holder for goto cat options #look at option file @ i = $i + 1 #increment counter at each pass echo options #echo options to screen echo -n "Enter your option... " #prompts user for selection set z=$< #sets user input to variable switch ($z) echo "" #inserts a blank line case [aA] #chosen if user selects option aA clear echo -n "Which file would you like to copy? " #prompts user for input set a=$< #sets user input to variable echo -n "What is the new filename? " #prompts user for input set new=$< #sets user input to variable cp $a $new #copies one file to another echo -n file $a was copied to $new #displays the file names echo "" #inserts a blank line goto top #return to the top and start over case [bB] #chosen if user selects option bB clear echo -n "Which file would you like displayed? " #prompts user for file n ame set f=$< #sets user input to variable if (-e $f) then #if the file exists then cat $f #cat the file endif #end if statement echo "" #inserts a blank line echo -n "Which column would you like to cut? " #prompts user for column to cut set c=$< #sets user input to variable cat $f|tr -s ' ' | cut -f $c -d ' '>duh2 #looks at file, removes spaces, cuts field and saves as new file echo "" #inserts a blank line cat duh2 #look at the edited file echo "" #inserts a blank line goto top #return to the top and start over case [cC] #chosen if user selects option cC clear echo -n "Enter the name of the file that you'd like to look at. " #promp ts user for input echo "" #inserts a blank line set f=$< #sets user input to variable cat $f #performs cat on user input goto top #return to the top and start over case [dD] #chosen if user selects option dD clear #clear screen loop: #place holder cat options1 #look at the options1 file for additional option s echo options1 #echo the options to the screen echo -n "Which function would you like to perform? " set i=$< #sets user input to variable switch ($i) case [1] clear echo -n "Which directory would you like to look at? " #ls comman d, prompts for directory set dir=$< #sets user input to variable. ls -alF $dir #performs ls on directory from user input echo "" #inserts a blank line goto loop #go to loop placeholder case [2] clear echo "" #inserts a blank line who #performs who echo "" #inserts a blank line goto loop #go to loop placeholder case [3] echo "" #inserts a blank line echo -n "What is the address to ping? " #prompts user for addres s to ping set address=$< #sets user input to variable ping $address -c 1 #performs ping, on user input, for one c ount echo "" #inserts a blank line goto loop #go to placeholder case [4] clear echo "Who would you like to 'finger'?" #prompts user for name set n=$< #sets user input to variable finger $n #performs finger on variable echo "" #inserts a blank line goto loop #go to placeholder case [5] goto top #go to placeholder endsw #end switch case [eE] #chosen if user selects option eE echo -n "You entered option e, to exit. Goodbye $name! $i options were c hosen. Your inputs were $z, $a, $new, $f, $c, $n, $dir, $address. " #ec ho the user's name, how many choices were made and what the inputs were. #displays which option was entered and exits the echo "" #inserts a blank line exit #exit breaksw #ends endsw #end the switch end #end the while statement |
So, what is it exactly that you have problems with?
Show debug output, or a thorough explanation of your problem, instead of posting the assignment. And please edit your post and put the code in BB code tags for readability. |
Hello, not sure if I did the BB code right, and I'm not fully sure what I'm being asked to do. What I attached was an example of what i'm being asked to do, so maybe you can help me alter it ? I never have been able to wrap my brain around this script making, so i'm desperate for help but I will try to answer any questions you have. Also my intro to programming has me doing something similar could I shoot you what I have with that to see what you think?
Tyvm, Chris Quote:
|
Quote:
Quote:
* Just so there'll be no misunderstanding: do not expect us provide you with a complete, grading-ready homework assignment. Like your assignments goal is to force you to think through the scripting process we try to achieve the same by asking questions. Learning takes time. |
All times are GMT -5. The time now is 07:31 AM. |