943,973 Members | Top Members by Rank

Ad:
Nov 14th, 2007
0

Shell program, help required.

Expand Post »
Ok, my name is Paul and i am new to this forum. I need some help and thought i can try my luck here. I need to write a program to do the following:

1. Need to write a shell script called fileutils.sh that will do:

Accept one variable on the command line and use the information stored in the variable in the script. Once inside the script the argument shold be given meaningful name and not reffered as $1
The single command line argument is the name of a log file to track the actions of the user during the life of the program must be used : ./fileutils myfile.log

Every time the user makes a menu selection, the selection made, along with the date/time of making the selection, should be sent to the log file(myfile.log)

2. print the following menu on the screen and perform the required operations dictated by the menu item:

1.make a new directory
2.list out the contents of a file.
3.safely delete a file
4.produce statistical information using an ‘awk script’
5.display the full name of any user.
6.display the log file.
0.exit the program

3.the menu must be repeated for the user once an option has been completed so that they may choose another option.

1 – make a new directory (mkdir.sh) should include
-read in directory name
-check if it exists
-if it does, warn the user
-otherwise create it

2 – list out the contents of a file(list,sh) should include
-read file name
-check if it exists and s a file
-list contents

3 –safely delete a file(safedel.sh)should include
-the file can be recovered if the deletion was a mistake

4 –run an awk script (I am going to start this part bit later, we just started awk programming)

5 –display the full name of any user (display.sh) should include
-read in the login name
-find this in /etc/passwd
-display the login name and full user name only using cut and determine whether the user is logged in
-print a message uf the user does not exist

6 –display the log file

0 –exit the program

#!/bin/bash
#
clear

#Setup logging
log=myfile.log
echo "--------------------------------" >> $log
date >> $log

keeploop=1
while [ $keeploop = 1 ]
do

#Print the menu
echo ""
echo "1 - Make a new directory"
echo "2 - List contents of a file"
echo "3 - Delete a file "
echo "4 - Produce Statistics"
echo "5 - Display name of User"
echo "6 - Display Log file"
echo "0 - Exit"
echo ""

read choice
echo ""
echo "Operator chose $choice" >> $log
echo ""

case "$choice" in

"1")
# Make a new directory
echo "Name of directory you wish to create?"
read newdir
echo ""
echo "Creating $newdir"
echo ""
mkdir $newdir
ls -dl $newdir
echo ""
;;

"2")
# cat a fiile
echo "Name of file you wish to print to screen?"
read catfile
echo "--------------------------------------------------------"
cat $catfile
echo "--------------------------------------------------------"
;;

"3")
# Delete a file
;;

"4")
# Statistics
;;

"5")
# User information
;;

"6")
# log file
;;

"0")
echo "Exiting"
echo "Exiting at" >> $log
date >> $log
keeploop=0
;;

esac

done

Ok, so far i managed to get to this step. I am unsure how to perform step number 5/6. I should be able to finish step 3 with a success. Can you guys help me out a little? Much appreciated.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
number1029 is offline Offline
2 posts
since Nov 2007
Nov 15th, 2007
0

Re: Shell program, help required.

Anyone? I need to get this done in next 3 weeks, any tips maybe?

Thank you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
number1029 is offline Offline
2 posts
since Nov 2007
Nov 16th, 2007
0

Re: Shell program, help required.

Hey There,

For step 5, ask for user input like in your other steps and then use that information and run "finger" or grep out of /etc/passwd and format as you like.

For step 6 - just use cat - I don't know which system log you'd be looking for - /var/adm/messages, /var/log/syslog, etc

That should be all you need to do

, Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: need help with writing shell script
Next Thread in Shell Scripting Forum Timeline: shell script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC