User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,439 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,613 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 674 | Replies: 2
Reply
Join Date: Nov 2007
Posts: 2
Reputation: number1029 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
number1029 number1029 is offline Offline
Newbie Poster

Shell program, help required.

  #1  
Nov 14th, 2007
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Posts: 2
Reputation: number1029 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
number1029 number1029 is offline Offline
Newbie Poster

Re: Shell program, help required.

  #2  
Nov 15th, 2007
Anyone? I need to get this done in next 3 weeks, any tips maybe?

Thank you.
Reply With Quote  
Join Date: Oct 2007
Posts: 306
Reputation: eggi is on a distinguished road 
Rep Power: 2
Solved Threads: 29
eggi eggi is offline Offline
Posting Whiz

Re: Shell program, help required.

  #3  
Nov 16th, 2007
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
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:42 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC