05-30-2002
Tell yas what, I'll just post the whole file here, 'cept that I'll remove a few comments (The language leaves something to be desired)
#!/bin/sh
#Menu bit
if [ $# -ne 2 ]
then
echo Invalid number of argumeents
echo
echo "Usage: $0 Arguement 1 Arguement 2 - No spaces please"
else
$1=log_file
$2=log_file2
echo ----------------
echo ---Main--Menu---
echo ----------------
echo
echo "1. Backup files"
echo
echo "2. Restore Backed-up files"
echo
echo "3. View Logs"
echo
echo "4. Quit"
echo
echo Please enter your selection
read selection
case $selection in
1) if [ ! -d backup ]
then
mkdir backup
else
#Beaut, now that we've either created the backup directory, or verified
#that it exists, let's ask the user kindly which file they'd like
#backed-up
fname=cont
function=B
while [ "$fname" != "quit" ]
do
echo Please Enter a the name of a file to backup
read fname
if [ -f $fname ]
then
echo Backing up $fname, please wait
echo ......
#Marker Line 50
cp $fname backup/$fname.bak
echo Successfully backed-up file $fname
echo `date`:$dname/$fname:$function >> $log_file
#Rightio, now that it's backed-up, let's ask them to either enter another
#file to backup, or to go back to the menu
fi
done
fi
;;
2)
#Ok, now we've got to restore the file, basically the same as the backup
#in theory, just a little different.....
if [ ! -d backup ]
then
echo The backup directory is either missing, or has been deleted, you therefore
echo cannot use this function
else
#Beaut, now that we've either created the backup directory, or verified
#that it exists, let's ask the user kindly which file they'd like
#backed-up
fname=cont
function=R
while [ "$fname" != "quit" ]
do
#Marker Line 75
echo Please Enter a the name of a file to restore
read fname
if [ -f $fname ]
then
echo
echo Please enter a directory to restore $fname to
read dname
if [ -d $dname ]
then
if [ -r $dname/$fname ]
then
echo Restoring $fname, please wait
echo "......"
else
echo "File already exists in $dname, Do you want it replaced?"
echo yes or no
read choice
if [ "$choice" = "yes" ]
then
echo Now restoring $fname
cp backup/$fname $dname
echo `date`:$dname/$fname:$function >> $log_file
echo Successfully restored $fname
else
echo You've chosen not to over-write the older file
echo
echo "Quitting due to unforseen circumstance......."
exit
#Rightio, now that it's restored, let's ask them to either enter another
#file to restore, or to go back to the menu
fi
fi
fi
fi
done
fi
;;
#Marker Line 100
3) #Damn thing doesn't want to check if a directory exists, so bugger it, I'll just create it
#I'm really starting to dislike UNIX.....
#mkdir logs
echo -----------
echo -Logs-Menu-
echo -----------
echo
echo "1. Search Logs for a file"
echo
echo "2. View all sorted by date / time"
echo
echo "3. View by type (Backup or Restore)"
echo
echo "4. Quit"
echo
echo Please make your selection
read selection
case $selection in
1) #Search logs for something
echo Please enter a file name to search for
read searchname
cd logs
grep $searchname *.*
grep $searchname >> log_file2
;;
2) #View all sorted by date / time
echo Displaying all log files
more *.*
;;
3) #View by type
echo Please enter what type you want
echo "(B for backup or R for restore)"
read choice
if [ $choice = "B" ]
then
cd logs
grep B *.*
else
grep R *.*
fi
;;
4) #Quit
exit
;;
esac
fi
exit
This might help yas, if anything it'll show you all how NOT to program in Unix, hahahaha.
Thanks
Aussie_Bloke
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi, I'm having trouble with some UNIX Bourne shell scripting that I am doing for an assignment.
I am trying to sort a comma delimited file into a sort of format that will print out nicely in a telnet terminal window. I'm having a bit of trouble because all I seem to be getting is garble.
... (3 Replies)
Discussion started by: Slamo
3 Replies
2. Shell Programming and Scripting
4. Write a program that will allow a user to input as many numbers as the user wants (use 999 as the choice that ends the user input). The program will then respond:
Highest Number: Answer
Lowest Number: Answer
Sum of the numbers: Answer
Average of the numbers: Answer
Can any1 help... (1 Reply)
Discussion started by: PoloRL185
1 Replies
3. Shell Programming and Scripting
hey,
i have 2 files... orders and products
how do i do calculations on the order using the products ?
say if the products file is:
a123:shirt:10.00
zz123:nice shirt:19.95
and the order file is:
05/08/30 a123 10
zz123 3
Jun-3-1994 a123 2
2005.06.23 a123 2 (1 Reply)
Discussion started by: ganjakh0r
1 Replies
4. UNIX for Dummies Questions & Answers
hey,
i have 2 files... orders and products
how do i do calculations on the order using the products ?
say if the products file is:
a123:shirt:10.00
zz123:nice shirt:19.95
and the order file is:
05/08/30 a123 10
zz123 3
Jun-3-1994 a123 2
2005.06.23 a123 2 (1 Reply)
Discussion started by: ganjakh0r
1 Replies
5. UNIX for Dummies Questions & Answers
Hi guys !!
well i'm still new in learning UNIX , and actually i'm still studying it by myself ..
anyway, some people told me the Bourne-again shell is a good version of UNIX to work on , and i tried to download yesterday but i didn't know how to start it ...... the ReadMe file associated with... (3 Replies)
Discussion started by: mrsamer
3 Replies
6. Shell Programming and Scripting
I do not claim to be an expert, but I have done things with scripts that whole teams of folks have said can not be done. Of course they should have said we do not have the intestinal fortitude to git-r-done.
I have been using UNIX actually HPUX since 1992. Unfortunately my old computer died and... (7 Replies)
Discussion started by: awk_sed_hello
7 Replies
7. Shell Programming and Scripting
Hi All
I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell.
Some operations like calculation don't work :
cat ${file1} | tail -$((${num1}-${num2})) > ${file2}
Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies
8. Shell Programming and Scripting
Exercise Five
Write a Bourne shell script which:
• Professionalism: plan for this from the start.
• Has one command line argument.
• If the command line argument is a directory then the script should output the number of
files in the directory.
• If the command line argument is an ordinary... (2 Replies)
Discussion started by: moesom
2 Replies
9. Shell Programming and Scripting
Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command ..
$ echo $SHELL
yields me
/bin/sh
Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies
10. Cybersecurity
A severe vulnerability was discovered in Bourne shell.
Just google for: bash vulnerability
... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies