Bourne Shell Scripting CRISIS


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bourne Shell Scripting CRISIS
# 8  
Old 05-30-2002
Looking at your last post and focusing on the section between the first ** and the last **, I continue to see the "else" clause of an "if" statement that is missing a terminating "fi". This has the effect of placing the line:
4) #Quit **
inside the "else" clause of the "if" statement where it is unexpected.

It's great that you found this problem. But now you need to actually insert the "fi" in your code.
# 9  
Old 05-30-2002
Rightio fellas (No offense)

Now that the mongrel code seems to have been conquered (At least for the moment)

But now it seems that the ending of the file has given Unix the chance to have another shot at me and my bad programming....

It now claims that, again within the section of code provided, it's found an unexpected End of file

How about I include an edited version of the complete file, so that you smart people (I know I'm sucking-up here, but I've got goodd reason too, it's not everyday that you get to contact the UNIX gods.....) can perhaps find another spot that could be stuffing the whole thing up?
Although for the moment, to spare those who have slower connections, I'll just put in the code required

Included code:

grep R *.*
fi
;;
4) #Quit
exit
;;
esac
fi
exit

You'll notice that there's a few parts missing, including the ending of the first case statement, I've chosen to do this for error checking, and have found that there is a problem with it, which really bugs me (No pun intended)
It's included below:

4) #Quit
exit
;;
*) #Bad choice
echo "Invalid menu selection, please enter a valid choice"
;;

esac

Cheers again all
# 10  
Old 05-30-2002
I can't see the end-of-file problem from what you have posted. But I'm pretty sure that you have another incomplete compound command somewhere. Compound commands are "if", "case", etc. One way to find these is pull out code until it's obvious. For example, remove an inner "case" statement and see if the problem disappears.
# 11  
Old 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
# 12  
Old 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.

The file was properly formatted (IE: Tabbed in) but I'm unable to fix this, as I'm too tired at the mo'
Too many early mornings (2-3:30am) are taking their toll

Thanks

Aussie_Bloke
# 13  
Old 05-30-2002
One problem - two case statements but only one esac in the script.

Another thing - you set a variable (selection) on both case statements - this may confuse it - change one to something else.
thehoghunter
# 14  
Old 05-30-2002
Alright, have done that, but I'm still getting unexpected end of file messages
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Cybersecurity

'Shell Shock' vulnerability in Bourne shell

A severe vulnerability was discovered in Bourne shell. Just google for: bash vulnerability ... for more details. (5 Replies)
Discussion started by: Cochise
5 Replies

2. Shell Programming and Scripting

Bourne shell & Korn shell

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

3. Shell Programming and Scripting

Bourne/C shell help

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

4. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

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

5. Shell Programming and Scripting

I need to understand the differences between the bash shell and the Bourne shell

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

6. UNIX for Dummies Questions & Answers

Bourne-again shell

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

7. UNIX for Dummies Questions & Answers

bourne shell programming help!

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

8. Shell Programming and Scripting

bourne shell programming help

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

9. Shell Programming and Scripting

Bourne Shell scripting help

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

10. Shell Programming and Scripting

Bourne Shell 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
Login or Register to Ask a Question

Featured Tech Videos