Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email my output, for every option I choose

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
I have a unix script, which displays a menu with options. Every menu has a sub_menu with its own options.
The sub-menu's all run different select statements from the database.
I would like to know what i need to change for each menu function to email its own output for the option chosen.
here is my script
Code:
#!/bin/ksh
WORKDIR=/u1/home/dba
LOGS=/u1/home/dba/logs
LOGO=" DBA MISCELLANEOUS MENU - 03.MISCELLANEOUS "
SYSTEM_001P=`cat /var/opt/oracle/SYSTEM_001P`

. /sun5/profiles/oracle_MAC.env

Displaymenu () {
clear
echo `date`
echo
echo "\t\t\t" $LOGO
echo
echo "\t\t"
echo "\t\t\t Select Option:"
echo
echo "\t\t\t [1]  Database uptime"
echo "\t\t\t [2]  Rman backup in last 24 hours"
echo "\t\t\t [3]  Information for running jobs"
echo "\t\t\t [4}  Scheduled job information"
echo "\t\t\t [5]  Extended_stats informations"
echo "\t\t\t [6]  Profiler runs on DB"
echo "\t\t\t [7]  All invalid objects on DB"
echo "\t\t\t [8]  All DB directories"
echo "\t\t\t [9]  "
echo "\t\t\t [10]  "
echo "\t\t\t [10]  "
echo "\t\t\t [11] "
echo "\t\t\t [99] Exit Program "
echo
echo "Enter option then ENTER to continue: \c"
}
PressEnter () {
echo Press Enter
read x
}
# A function for each of the menu picks

db_uptime()
{
  echo " Display Database uptime "
  do_db_uptime
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
 }

do_db_uptime()
{
SPOOLFILE=$WORKDIR/0301_db_uptime
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0301_db_uptime.sql
exit;
ENDOFSQL
}

rman_last24()
{
  echo " Run rman backups for last 24 hours "
  do_rman_last24
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
}

do_rman_24()
{
SPOOLFILE=$WORKDIR/0302_rman_last24.txt
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0302_rman_last24.sql
exit;
ENDOFSQL
}

list_run_jobs()
{
  echo " Information for running jobs "
  do_run_jobs
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
}

do_run_jobs()
{
SPOOLFILE=$WORKDIR/0303_list_run_jobs.txt
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0303_list_run_jobs.sql
exit;
ENDOFSQL
}

job_info()
{
  echo " Scheduled job information "
  do_job_info
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
}

do_job_info()
{
SPOOLFILE=$WORKDIR/0304_job_info.txt
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0304_job_info.sql
exit;
ENDOFSQL
}

extended_stats()
{
  echo " information about extended statistics "
  do_extended_stats
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
}

do_extended_stats()
{
SPOOLFILE=$WORKDIR/0305_extended_stats.txt
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0305_extended_stats.sql
exit;
ENDOFSQL
}

profiler_runs()
{
  echo " Information on all profiler_runs "
  do_profiler_runs
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
}

do_profiler_runs()
{
SPOOLFILE=$WORKDIR/0306_profiler_runs.txt
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0306_profiler_runs.sql
exit;
ENDOFSQL
}

invalid_objects()
{
  echo " Lists all invalid objects in the DB "
  do_invalid_objects
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
}

do_invalid_objects()
{
SPOOLFILE=$WORKDIR/0307_invalid_objects.txt
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0307_invalid_objects.sql
exit;
ENDOFSQL
}

db_direct()
{
  echo " Information about all DB directories "
  do_db_direct
  echo " Enter email address then enter to continue: \c"
  read EMAIL
  echo $EMAIL
  do_email
  PressEnter
}

do_db_direct()
{
SPOOLFILE=$WORKDIR/0308_db_directories.txt
sqlplus -s sys/${SYSTEM_001P} AS SYSDBA <<ENDOFSQL
@${WORKDIR}/0308_db_directories.sql
exit;
ENDOFSQL
}

do_email()
{
  echo "Emailing report now"
SUBJECT=" (Sun5) List Profile Report "
TO=oradba
(
cat $SPOOLFILE
) | /usr/local/bin/mutt -s "$SUBJECT" -a $SPOOLFILE $EMAIL
}
while true
do
    Displaymenu
    read answer
    case $answer in
         1)  db_uptime;;
         2)  rman_last24;;
         3)  list_run_jobs;;
         4)  job_info;;
         5)  extended_stats;
         6)  profiler_runs;;
         7)  invalid_objects;;
         8)  db_direct;;
         9)  ;;
         10) ;;
         99) break ;;
    esac
done
clear

Any help will be much appreciated
 
Not sure I'm totally on the same page, but mutt likes to sit and wait for input for the message body.

I normally avoid that by reding body contents from dev/null when just sending attachmets:

mutt -s"subject line" -a attachment recipient@somewhere.com </dev/null

Cheers
K

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top