Sponsored Content
Top Forums Shell Programming and Scripting Nee help debugging script..plz Post 302096638 by BOFH on Thursday 16th of November 2006 09:07:52 PM
Old 11-16-2006
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$

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HP-UX Debugging Shell script

Hi, I was using AIX - ksh shell , and inorder to debug shell script I used set -vx to echo all the commands which are being executed. Can anybody tell me the corresponding method in HP-UX - in tcsh shell. Regards Shihab (1 Reply)
Discussion started by: shihabvk
1 Replies

2. Shell Programming and Scripting

FTP script debugging

Hello all, I am trying to run a script and have not had much success running it...ne help debugging it will be appreciated..The ftp script alone works but not within the while loop. below is the script #!/usr/bin/ksh destination_server=servename destination_user_id=un... (1 Reply)
Discussion started by: alfredo123
1 Replies

3. Shell Programming and Scripting

debugging a script??

Hi all, Am working on a script to understand the flow control of it.. Since i am from a C background i looking out for an easy way to analyze the script as it runs .. In C/C++ we have F7 that starts execution from main() and proceeds accordingly.. I was wondering if there is a same approach... (2 Replies)
Discussion started by: wrapster
2 Replies

4. UNIX for Advanced & Expert Users

cp script error, pls help in debugging!!!!

Hi all, I searched to find out a few cp scripts that had progress bar, but did not compromise on performance, when my efforts were in vain i went ahead and wrote one of my own ,taking i/p frm other scripts... But this is causing some errors and am unable to debug it.....pls help Here is the... (1 Reply)
Discussion started by: wrapster
1 Replies

5. UNIX for Advanced & Expert Users

Command nee to cut the record

I have a file which contains a record like follows /dir1/dir2/dir3/file.dat I need command to so that output can be only file.dat (6 Replies)
Discussion started by: sreenusola
6 Replies

6. Shell Programming and Scripting

script debugging

is there any way you can add a breakpoint in a script so you can stop on it? i have used -xv in my shebang but the script just runs and i want it to stop at a specific point in the script. appreciate any help. (1 Reply)
Discussion started by: npatwardhan
1 Replies

7. Shell Programming and Scripting

debugging the shell script with out actually running

Hello, Some one asked me in the inteview.... The question is, How do we debug the schell script before even running..... Interviewer told me one clue... There is SET command to accomplish this... Can any one tell me what kind of set commands.... Thanks. (2 Replies)
Discussion started by: govindts
2 Replies

8. Shell Programming and Scripting

Debugging a script with noexec

Newbie question. I cannot get "set -n" or "set -noexec on" to work on Linux or AIX! According to the man page and what I read online, it should inform me of syntax errors without executing commands in your script. So, can someone PLEASE explain why this does not work? ... (2 Replies)
Discussion started by: fgoyti
2 Replies

9. Shell Programming and Scripting

Shell script debugging

hi all only the weirdest thing happened with me just now. I was debugging a shell script and I found that a step that was supposed to execute later was getting executed prior to another step for no reason. You know any ? i mean have a look at the following command- here it tries to grep... (7 Replies)
Discussion started by: leghorn
7 Replies
All times are GMT -4. The time now is 09:42 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy