![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| cp script error, pls help in debugging!!!! | wrapster | UNIX for Advanced & Expert Users | 1 | 05-24-2008 08:12 AM |
| which one method is best for debugging the shell script? | psiva_arul | UNIX for Advanced & Expert Users | 2 | 05-20-2008 06:33 AM |
| debugging a script?? | wrapster | Shell Programming and Scripting | 2 | 03-25-2008 11:07 AM |
| FTP script debugging | alfredo123 | Shell Programming and Scripting | 1 | 11-08-2006 01:22 PM |
| HP-UX Debugging Shell script | shihabvk | Shell Programming and Scripting | 1 | 04-24-2006 09:55 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Nee help debugging script..plz
I am having problems w/this script. Menu is not comming up to prompt me. I've worked on it for days and still cannot see the problem. Anyone can help, I would appreciate it. Possible problems with syntax and function calls.
Thks... TMP=$tapemgr/rpts/tmp # TAPE MANAGER MAIN MENU while : do clear tapemgr_Main_Menu() { echo " Tape Management System Menu" echo "This system is used to report Legato ERV Offsite and Tapes Returned" 1. BUR IPS Tape Offsite Report 2. BUR IPS TAPE Returns from ERV q. Quit or Ctrl-C echo "Select an option 1,2,q" read option case $option in 1) Tapes_Offsite_Menu();; 2) Tapes_Return_Menu();; q) exit;; esac done } Tapes_Offsite_Menu() { echo "Select an option for Offsite Report - '(W)'eekly '(M)'onthly '(B)'oth" read option case $option in W)Weekly_Offsite();; M)Monthly_Offsite();; B)Both_Offsite();; x)tapemgr_Main_Menu();; esac } Tapes_Return_Menu() { echo "Tapes Return Menu" echo "Enter IPS tape '(V)olumes or (D)ates to be returned'" echo "R - Return to Main Menu" case $SEL in V) Volume_Returns();; D) Volume_Date_Returns();; r) tapemgr_Main_menu();; esac } Volume_Returns() { echo "Enter Volumes to be returned", read $input mminfo -q volume=$1 -q location=ERV | awk {'print $1'} # if [location =! "ERV" ]; then echo " volume does not exist at ERV" # fi } Volume_Date_Returns() { echo "Return of all '"expired"' ERV tapes '(y/n)'" # if $1 = "y", then mminfo -q volrent=expired -q location=ERV -r volume,volretent,pool | more > $TMP/vol.out echo " Is this list the correct list of tapes to be returned?" # if $1 == "y", then next echo "Enter date of tapes to be returned '(mm/dd/yy or enter today, yesterday, last week)'", read $1 # if $1 = ?? mminfo -q volretent=$1 -q location=ERV -r volume, volrent,pool |more $TMP/vol.out # fi } ## Run Weekly Offsite Report Weekly_Offsite() { echo "$dat BURS Weekly Offsite STK9310 Tape Report " > $WOFFSITE mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Weekly" -q location="STK9310" >> $WOFFSITE >$EJECT_TAPES echo "Total WEEKLY OFFSITE IPS TAPES " | wc -l | $WOFFSITE > $OFFSITE_REPORT >$EMAIL_NOTICE TMP_FILES() FTP_FILES() EMAIL_NOTIFICATION() } ## Run Monthly Report Monthly_OffSite() { echo "$dat BURS Weekly Offsite STK9310 Tape Report " > $MOFFSITE mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Monthly" -q location="STK9310" >> $MOFFSITE >$EJECT_TAPES echo "TOTAL Monthly Offsite IP Tapes" | wc -l $MOFFSITE > $OFFSITE_REPORT > $EMAIL_NOTICE TMP_FILES() FTP_FILES() EMAIL_NOTIFICATION() } #### Both or Any Tapes that should be offsite Monthly or Weekly Both_Offsite() { echo "$dat BURS Any Offsite STK9310 Tape Report " > $BOFFSITE mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Monthly" -q location="STK9310" > $BOFFSITE >$EJECT_TAPES mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Weekly" -q location="STK9310" >> $BOFFSITE >>$EJECT_TAPES echo " Total IPS Tapes going Offsite" | wc -l $BOFFSITE >> $BOFFSITE >> EMAIL_NOTICE TMP_FILES () FTP_FILES() EMAIL_NOTIFICATION() } ### Send Email Notification EMAIL_NOTIFICATION() { echo "mail function" } # Create TMP Files for cuting and pasting TMP_FILES() { cut -c1-8 $EJECT_TAPES | sort +1 > $TMP/eject_sort.out } # FTP FILES TO HOST SERVER FTP_FILES() { ftp -n $FTP_HOST <<END_SCRIPT quote USER $FTP_LOGIN quote PASS $FTP_PWD END_SCRIPT } bash-2.05$ |
|
||||
|
Ok, the first thing is you need to post the complete script. You're missing the top of the script since I don't see the #!/bin/bash line.
Next is use the code tags to enclose your script to make it easier to read. Hard to say if an error is due to transcription or just because the software is deleting spaces and brackets. Next is the Main_Menu function is not right. You have the while, do and clear outside of the function instead of inside. Next is you aren't echoing the menu options. The Volume_Date_Returns function has some bogus if statement constructs. They're commented out but they should be corrected if you're going to use them. The rest looks basically ok. I'm not 100% sure on how you're using if statements. I'm pretty sure you need to use brackets to enclose the test. I always do and like to verify it before saying it for sure. Can't hurt to actually enclose in brackets though. Fixed Main_Menu: Code:
tapemgr_Main_Menu()
{
while : do
clear
echo " Tape Management System Menu"
echo "This system is used to report Legato ERV Offsite and Tapes Returned"
echo "1. BUR IPS Tape Offsite Report"
echo "2. BUR IPS TAPE Returns from ERV"
echo "q. Quit or Ctrl-C"
echo "Select an option 1,2,q"
read option
case $option in
1) Tapes_Offsite_Menu();;
2) Tapes_Return_Menu();;
q) exit;;
esac
done
}
|
|
||||
|
Still having issues
This is the error I am getting now..below is the entire script. I am having to peicemeal the testing of it..till I can figure it all out. Thanks for anyhelp you can assist with.
tapemgr_Main_Menu() { while : do echo "Legato Tape Management System Menu" echo "This system is used to report Legato ERV Offsite and Tapes Returned" echo "1. BUR IPS Tape Offsite Report" echo "2. BUR IPS TAPE Returns from ERV" echo "q. Quit or Ctrl-C" echo "Select an option 1,2,q" read option case $option in 1) Tapes_Offsite_Menu();; 2) Tapes_Return_Menu();; q) exit;; esac done tapemgr.sh: syntax error at line 41: `done' unexpected bash-2.05$ Entire script after your corrections... # Tape Manager Menu for Legato IPS Reporting for Offsite and Return tapes # #!/bin/bash # # Defing all variables set -x rm -i $tapemgr/rpts/*.* dat=`date +"%b%y"` tapemgr="/export/home/legato/tapemgr" ERVTAPE_RET=$tapemgr/rpts/ervtape_ret.$dat ERVTAPE_ALOC=$tapemgr/rpts/tmp/ervtape__aloc MOFFSITE=$tapemgr/rpts/offsite/Mthly_Offsite.rpt.$dat WOFFSITE=$tapemgr/rpts/offsite/Wkly_Offsite.rpt.$dat BOFFSITE=$tapemgr/rpts/offsite/Both_Offsite.rpt.$dat EMAIL_NOTICE=$tapemgr/rpts/email.rpt$dat FTP_HOST='xxx' FTP_LOGIN='xxx' FTP_PWD='xxx' EJECT_TAPES=$tapemgr/rpts/tmp/eject_tapes.out TMP=$tapemgr/rpts/tmp # TAPE MANAGER MAIN MENU clear tapemgr_Main_Menu() { while : do echo "Legato Tape Management System Menu" echo "This system is used to report Legato ERV Offsite and Tapes Returned" echo "1. BUR IPS Tape Offsite Report" echo "2. BUR IPS TAPE Returns from ERV" echo "q. Quit or Ctrl-C" echo "Select an option 1,2,q" read option case $option in 1) Tapes_Offsite_Menu();; 2) Tapes_Return_Menu();; q) exit;; esac done } Tapes_Offsite_Menu() { while:do echo "Select an option for Offsite Report - '(W)'eekly '(M)'onthly '(B)'oth" read option case $option in W)Weekly_Offsite();; M)Monthly_Offsite();; B)Both_Offsite();; x)tapemgr_Main_Menu();; esac done } Tapes_Return_Menu() { while:do echo "Tapes Return Menu" echo "Enter IPS tape '(V)olumes or (D)ates to be returned'" echo "R - Return to Main Menu" case $SEL in V) Volume_Returns();; D) Volume_Date_Returns();; r) tapemgr_Main_menu();; esac done } Volume_Returns() { echo "Enter Volumes to be returned", read $input mminfo -q volume=$1 -q location=ERV | awk {'print $1'} # if [location =! "ERV" ]; then echo " volume does not exist at ERV" # fi } Volume_Date_Returns() { echo "Return of all '"expired"' ERV tapes '(y/n)'" # if $1 = "y", then mminfo -q volrent=expired -q location=ERV -r volume,volretent,pool | more > $TMP/vol.out echo " Is this list the correct list of tapes to be returned?" # if $1 == "y", then next echo "Enter date of tapes to be returned '(mm/dd/yy or enter today, yesterday, last week)'", read $1 # if $1 = ?? mminfo -q volretent=$1 -q location=ERV -r volume, volrent,pool |more $TMP/vol.out # fi } ## Run Weekly Offsite Report Weekly_Offsite() { echo "$dat BURS Weekly Offsite STK9310 Tape Report " > $WOFFSITE mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Weekly" -q location="STK9310" >> $WOFFSITE >$EJECT_TAPES echo "Total WEEKLY OFFSITE IPS TAPES " | wc -l | $WOFFSITE > $OFFSITE_REPORT >$EMAIL_NOTICE TMP_FILES() FTP_FILES() EMAIL_NOTIFICATION() } ## Run Monthly Report Monthly_OffSite() { echo "$dat BURS Weekly Offsite STK9310 Tape Report " > $MOFFSITE mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Monthly" -q location="STK9310" >> $MOFFSITE >$EJECT_TAPES echo "TOTAL Monthly Offsite IP Tapes" | wc -l $MOFFSITE > $OFFSITE_REPORT > $EMAIL_NOTICE TMP_FILES() FTP_FILES() EMAIL_NOTIFICATION() } #### Both or Any Tapes that should be offsite Monthly or Weekly Both_Offsite() { echo "$dat BURS Any Offsite STK9310 Tape Report " > $BOFFSITE mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Monthly" -q location="STK9310" > $BOFFSITE >$EJECT_TAPES mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Weekly" -q location="STK9310" >> $BOFFSITE >>$EJECT_TAPES echo " Total IPS Tapes going Offsite" | wc -l $BOFFSITE >> $BOFFSITE >> EMAIL_NOTICE TMP_FILES () FTP_FILES() EMAIL_NOTIFICATION() } ### Send Email Notification EMAIL_NOTIFICATION() { echo "mail function" #mailx -s "$dat BURS-Offsite IPS Tape Report" < $EMAIL_NOTICE am001111@eds.com kathe.flanigan@eds.com } # Create TMP Files for cuting and pasting TMP_FILES() { cut -c1-8 $EJECT_TAPES | sort +1 > $TMP/eject_sort.out } # FTP FILES TO HOST SERVER FTP_FILES() { ftp -n $FTP_HOST <<END_SCRIPT quote USER $FTP_LOGIN quote PASS $FTP_PWD END_SCRIPT } bash-2.05$ |
|
||||
|
Ok, step one. Use the code tags. When you go to create a message and you're including a script, click on the hash mark in the meny above the new message and then include your code.
There are a couple of problems in your script. 1. Don't call functions with the tailing parens. It fails. 2. Don't use ':' as your test statement. It works for if statements but not while statements. 3. Don't put tasks in the variable definitions section. It can get confusing. I moved the rm statement out, especially since you're trying to delete before the path variable was assigned. 4. The script would have run but wouldn't have presented a menu. It's all functions. Somewhere outside of the functions you need to run the first function. I added the commands at the end of the script. They must be after the functions are defined or you'll get a "I don't know what you're talking about" type of error. I've included the script you provided. I indented, added some extra lines and spaces, and made the necessary corrections. I've highlighted the main changes in red. In particular, I like having extra space between, for example the data and the open paren in case blocks or between the command and the double semi-colons. It just makes it easier to read, for me at least. And you need to remember that there will be someone else behind you trying to understand what you were doing. Also, I didn't run through the whole thing to make sure everything was working. I did find a missing read line (highlighted in the script) but there may be other errors. Feel free to ask again if you are still having trouble. Carl Code:
# Tape Manager Menu for Legato IPS Reporting for Offsite and Return tapes
#
#!/bin/bash
#
# Defing all variables
set -x
dat=`date +"%b%y"`
tapemgr="/export/home/legato/tapemgr"
ERVTAPE_RET=$tapemgr/rpts/ervtape_ret.$dat
ERVTAPE_ALOC=$tapemgr/rpts/tmp/ervtape__aloc
MOFFSITE=$tapemgr/rpts/offsite/Mthly_Offsite.rpt.$dat
WOFFSITE=$tapemgr/rpts/offsite/Wkly_Offsite.rpt.$dat
BOFFSITE=$tapemgr/rpts/offsite/Both_Offsite.rpt.$dat
EMAIL_NOTICE=$tapemgr/rpts/email.rpt$dat
FTP_HOST='xxx'
FTP_LOGIN='xxx'
FTP_PWD='xxx'
EJECT_TAPES=$tapemgr/rpts/tmp/eject_tapes.out
TMP=$tapemgr/rpts/tmp
# TAPE MANAGER MAIN MENU
tapemgr_Main_Menu()
{
while true
do
echo "Legato Tape Management System Menu"
echo "This system is used to report Legato ERV Offsite and Tapes Returned"
echo "1. BUR IPS Tape Offsite Report"
echo "2. BUR IPS TAPE Returns from ERV"
echo "q. Quit or Ctrl-C"
echo "Select an option 1,2,q"
read option
case $option in
1 ) Tapes_Offsite_Menu ;;
2 ) Tapes_Return_Menu ;;
q ) exit ;;
esac
done
}
Tapes_Offsite_Menu()
{
while true
do
echo "Select an option for Offsite Report - '(W)'eekly '(M)'onthly '(B)'oth"
read option
case $option in
W ) Weekly_Offsite ;;
M ) Monthly_Offsite ;;
B ) Both_Offsite ;;
x ) tapemgr_Main_Menu ;;
esac
done
}
Tapes_Return_Menu()
{
while true
do
echo "Tapes Return Menu"
echo "Enter IPS tape '(V)olumes or (D)ates to be returned'"
echo "R - Return to Main Menu"
read SEL
case $SEL in
V ) Volume_Returns ;;
D ) Volume_Date_Returns ;;
r ) tapemgr_Main_menu ;;
esac
done
}
Volume_Returns()
{
echo "Enter Volumes to be returned", read $input
mminfo -q volume=$1 -q location=ERV | awk {'print $1'}
# if [location =! "ERV" ]; then
echo " volume does not exist at ERV"
# fi
}
Volume_Date_Returns()
{
echo "Return of all '"expired"' ERV tapes '(y/n)'"
# if $1 = "y", then
mminfo -q volrent=expired -q location=ERV -r volume,volretent,pool | more > $TMP/vol.out
echo " Is this list the correct list of tapes to be returned?"
# if $1 == "y", then next
echo "Enter date of tapes to be returned '(mm/dd/yy or enter today, yesterday, last week)'", read $1
# if $1 = ??
mminfo -q volretent=$1 -q location=ERV -r volume, volrent,pool |more $TMP/vol.out
# fi
}
## Run Weekly Offsite Report
Weekly_Offsite()
{
echo "$dat BURS Weekly Offsite STK9310 Tape Report " > $WOFFSITE
mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Weekly" -q location="STK9310" >> $WOFFSITE >$EJECT_TAPES
echo "Total WEEKLY OFFSITE IPS TAPES " | wc -l | $WOFFSITE > $OFFSITE_REPORT >$EMAIL_NOTICE
TMP_FILES
FTP_FILES
EMAIL_NOTIFICATION
}
## Run Monthly Report
Monthly_OffSite()
{
echo "$dat BURS Weekly Offsite STK9310 Tape Report " > $MOFFSITE
mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Monthly" -q location="STK9310" >> $MOFFSITE >$EJECT_TAPES
echo "TOTAL Monthly Offsite IP Tapes" | wc -l $MOFFSITE > $OFFSITE_REPORT > $EMAIL_NOTICE
TMP_FILES
FTP_FILES
EMAIL_NOTIFICATION
}
#### Both or Any Tapes that should be offsite Monthly or Weekly
Both_Offsite()
{
echo "$dat BURS Any Offsite STK9310 Tape Report " > $BOFFSITE
mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Monthly" -q location="STK9310" > $BOFFSITE >$EJECT_TAPES
mminfo -r volume,volretent,pool,location -q pool="COE Full Offsite Weekly" -q location="STK9310" >> $BOFFSITE >>$EJECT_TAPES
echo " Total IPS Tapes going Offsite" | wc -l $BOFFSITE >> $BOFFSITE >> EMAIL_NOTICE
TMP_FILES
FTP_FILES
EMAIL_NOTIFICATION
}
### Send Email Notification
EMAIL_NOTIFICATION()
{
echo "mail function"
# mailx -s "$dat BURS-Offsite IPS Tape Report" < $EMAIL_NOTICE am001111@eds.com kathe.flanigan@eds.com
}
# Create TMP Files for cuting and pasting
TMP_FILES()
{
cut -c1-8 $EJECT_TAPES | sort +1 > $TMP/eject_sort.out
}
# FTP FILES TO HOST SERVER
FTP_FILES()
{
ftp -n $FTP_HOST << END_SCRIPT
quote USER $FTP_LOGIN
quote PASS $FTP_PWD
END_SCRIPT
}
clear
rm -i $tapemgr/rpts/*.*
tapemgr_Main_Menu
exit 0
#bash-2.05$
|
|
||||
|
Carl,
so far I've got the menu's working. Thank-you.. I am sure I will need more assistance, but will have to test each function as a piecemeal. I'm only a beginner, but I'm still learning. Thanks again..you'll her from me soon also. |
|
||||
|
Need an extra set of eyes to help me with the congested "if statement"..can you see where I might be bugging?
86 Volume_Date_Returns() 87 { 88 echo "Return of all '"expired"' ERV tapes '(y/n)'" 89 if [ $response = y ]; then 74 { 75 echo "Enter Volumes to be returned"; read input; echo $input 76 mminfo -q volume=$input -r volume,location,pool,volretent > $1 77 echo "Is this the volume you would like to return" 78 read response 79 if [ $response = y ]; then 80 echo " Please return the follow tapes $1" >$RETURN_REQUEST 81 else 82 echo "incorrect response" 83 exit 84 fi 85 } 86 Volume_Date_Returns() 87 { 88 echo "Return of all '"expired"' ERV tapes '(y/n)'" 89 if [ $response = y ]; then 90 mminfo -q volrent=expired -q location=ERV -r volume,volretent,pool &1>$TMP/vol.out 91 echo " Is this list the correct list of tapes to be returned?" 92 if [$response = y ] then 93 echo "List will be emailed to you" 94 else 95 if [$response = n "; then 96 echo "Enter date of tapes to be returned '(mm/dd/yy or enter (T)oday, (Y)esterday, (L)ast week)'" 97 read dates 98 mminfo -q volretent='$dates'-q location=ERV -r volume, volrent,pool |more $TMP/vol.out 99 fi |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|