INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Email my output, for every option I choose

Email my output, for every option I choose

(OP)
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

RE: Email my output, for every option I choose

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close