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.

Recommended Answers

All 2 Replies

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

Thank you.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.