•
•
•
•
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
![]() |
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
•
•
Join Date: Oct 2007
Posts: 306
Reputation:
Rep Power: 2
Solved Threads: 29
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
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!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
![]() |
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Make a VB Program run in the background? (VB.NET)
- shell issues (Visual Basic 4 / 5 / 6)
- grade prediction program (C)
- Help! C program w/Pointer Notation to Convert Text (C)
- help me--find command-shell program in unix (Shell Scripting)
- Problem with a snippet of code in a shell program (C)
- Another Program Launching mine (C++)
- stuck with definition (C++)
- How To Tweak Icon Sizes and so,Windows XP Startbar (Windows NT / 2000 / XP / 2003)
Other Threads in the Shell Scripting Forum
- Previous Thread: need help with writing shell script
- Next Thread: shell script


Linear Mode