Fedora Linux Support Community & Resources Center
  #1  
Old 6th May 2005, 11:59 AM
YianniArvani Offline
Registered User
 
Join Date: Apr 2005
Posts: 16
Shell script

Hey guys. I have two possible answers to this question. I dont think both work but im hoping someone can point out which way is best to use and which will work.


Question:

Write a shell script which will display a menu as follows
and accepts an input key from the user to execute an option
on the menu.

My Menu
~~~~~~~
1) Display today's date and system uptime
2) Display calendar for a particular month and year
3) Display current logon users
4) Find a file
5) Exit from menu
Please enter your choice (1-5):

For option 2, the user must be allowed to enter the month
and the year for calendar display. For option 4, you must
use the find command to find the file and the user must be
allowed to enter the file name and the name of the directory
for the search. Your shell script should run continuously
until the user enters 5 for exit.



Answer 1:

tput clear;
tput cup 3 17; echo “My Menu”;
tput cup 4 17; echo “~~~~~~~”;
tput cup 6 12; echo “1) Display today’s date and system uptime”;
tput cup 7 12; echo “2) Display calendar for a particular month and year”;
tput cup 8 12; echo “3) Display current logon users”;
tput cup 9 12; echo “4) Find a file”;
tput cup 10 12; echo “5) Exit from menu”;
tput cup 11 17; echo “Please enter your choice (1-5):”; tput cup 11 49;
read choice
if [ “$choice” = “1” ];
then
tput cup 12 17; date
else
if [ “$choice” = “2” ];
then
tput cup 12 17; echo “Please enter month:”; tput cup 12 37;
read month
tput cup 13 17; echo “Please enter year:”; tput cup 13 37;
read year
cal
else
if [ “$choice” = “3” ];
then
tput cup 12 17; who
else
if [ “$choice” = “4” ];
then
tput cup 12 17; echo “What is the name of the directory?”; tput cup 12 52;
read directory
tput cup 13 17; echo “What is the filename?”; tput cup 13 52;
read filename
tput cup 14 17; find /directory –name filename
else
exit
fi
fi
fi
fi



Answer 2:

#!/bin/bash

while true ; do
clear
tput cup 3 32; echo "My Menu"
tput cup 4 12; echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~"
tput cup 6 12; echo "1. Display today’s date and system uptime"
tput cup 7 12; echo "2. Display calendar for a particular month and year"
tput cup 8 12; echo "3. Display current logon users"
tput cup 9 12; echo "4. Find a file"
tput cup 10 12; echo "5. Exit from menu"
tput cup 11 17; echo -n "Please enter your choice (1-5): "

read sel

case $sel in
1) tput cup 13 17; echo -e "Todays date is `date`"
tput cup 14 17; echo -e "Uptime is `uptime |awk '{print$3}'`\n\n" ;;

2) tput cup 13 17; echo -n "Please enter month: " ;
read month
tput cup 14 17; echo -n "Please enter year (4 digits): " ;
read year
echo -e "\n\n`cal $month $year`\n\n" ;;

3) tput cup 13 17; who ;;

4) tput cup 13 17; echo -n "Name of the directory? " ;
read directory
tput cup 14 17; echo -n "What is the filename? " ;
read filename
tput cup 16 17; find $directory/$filename ;;

5) exit ;;

esac
sleep 10
done


--------------------
The UNIX software used at uni is called SSH

I would greatly appreciate if anyone could just let me know where i have gone wrong, what it should look like and which way is best.

Thank you in advanced. Took me hours to do this.
Reply With Quote
  #2  
Old 6th May 2005, 12:07 PM
YianniArvani Offline
Registered User
 
Join Date: Apr 2005
Posts: 16
This guy told me the second answer is right but when i tried it at uni it didnt work.

I dont have SSH at home ... looking to download it ... so i cant test and see if its right. Plus i have to prove it works to my tutor and i dont want to look like an idiot with a script that doesnt work.
Reply With Quote
  #3  
Old 6th May 2005, 12:14 PM
AndyGreen's Avatar
AndyGreen Offline
Registered User
 
Join Date: Apr 2005
Location: Northants, UK
Posts: 2,026
Quote:
Took me hours to do this.
I hope your schizo meds are working better later today then.
Dr Jekell: Multiple ifs are clearly superior to the case statement favoured by certain riffraff
Mr Hyde: RUAHH!!! Case Rules!!! Spavined gentrified nincompoop!
Dr Jekyll: Backticks are for the lower classes
Mr Hyde: GAGGGHHH!!! Backticks have their place in polite society!!! Gollum Gollum
Dr Jekyll: Cal is perfectly capable to guess which variable to take input from. Only a dullard from the scullery-kitchen could fail to apprehend this natural affinity for cal to appropriately named variables!
Mr Hyde: HUSSSS!!! Inbred imebcile.... I bet you voted Conservative
Dr Jekyll: Oh yes, I saw the "run continuously" requirement, but frankly, only a fool would require such a thing, so I ignored it as is my duty as a gentleman
Mr Hyde: PHHHHTTTTT!!! Your lack of knowledge offends by bestial nature! RUAHH!!!
Dr Jekyll: Aiieeee!!!
__________________
Freelance RedHat Certified Engineer - http://northantsIT.com
Reply With Quote
  #4  
Old 6th May 2005, 01:14 PM
YianniArvani Offline
Registered User
 
Join Date: Apr 2005
Posts: 16
Sorry mate, i didnt understand that post at all. Is there like a hidden message to it i should of worked out or something?
Reply With Quote
  #5  
Old 6th May 2005, 01:29 PM
AndyGreen's Avatar
AndyGreen Offline
Registered User
 
Join Date: Apr 2005
Location: Northants, UK
Posts: 2,026
I understood your post to be saying you wrote both versions, my post is saying it could not be the case. Unfortunately inbetween you rather destroyed the point of my post :-)

The second version works fine.
__________________
Freelance RedHat Certified Engineer - http://northantsIT.com
Reply With Quote
  #6  
Old 6th May 2005, 02:25 PM
YianniArvani Offline
Registered User
 
Join Date: Apr 2005
Posts: 16
Im only just learning this. I came up with the first.

This guy helped me and came up with the second.

Then when i checked it at uni both didnt work.

I probably should have been more clearer.

Thank you for your reply. You sure the second one works fine though?
Reply With Quote
  #7  
Old 6th May 2005, 02:26 PM
AndyGreen's Avatar
AndyGreen Offline
Registered User
 
Join Date: Apr 2005
Location: Northants, UK
Posts: 2,026
Yep, I tried it here before committing myself to saying that it worked.

What did not work when you tried it?
__________________
Freelance RedHat Certified Engineer - http://northantsIT.com
Reply With Quote
  #8  
Old 6th May 2005, 02:32 PM
YianniArvani Offline
Registered User
 
Join Date: Apr 2005
Posts: 16
No idea, which confussed me, unless i mis-typed something or left something out i have no idea.

Thanks heaps in checking it for me. When i can im going to check it out before executing it infront of my tutor.

Appreciate it mate, take care.
Reply With Quote
  #9  
Old 7th May 2005, 07:11 AM
YianniArvani Offline
Registered User
 
Join Date: Apr 2005
Posts: 16
It works.

I downloaded the SSH Secure Shell Client and copied and pasted it and it worked.

Before i typed it (only because im not sure if im allowed to copy and paste it in the SSH client to show if it works or not infront of the tutor so i typed it for prac)

Thanks for your help Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
call remote shell script within an expect script PhillyFloyd Programming & Packaging 2 16th October 2007 10:29 PM
starting a shell script inside a php script gw348 Using Fedora 6 23rd April 2007 09:30 PM
Shell Script remm692007 Programming & Packaging 2 13th April 2007 06:32 PM
need to run script Bourne-shell script armen Using Fedora 4 4th April 2005 01:16 PM
Shell script ieuuk Programming & Packaging 5 28th October 2004 10:51 PM


Current GMT-time: 21:11 (Saturday, 25-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat