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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unix script using a menu

Status
Not open for further replies.

grapes12

Technical User
Mar 2, 2010
124
ZA
A simple menu to call a SQL and email output to a user:
here is what i have:
#!/bin/ksh
WORKDIR=/u1/home/ops
SPOOLFILE=/u1/home/ops/menopt15.lst
LOGO="Users Takeon/Expired"
LIST="xxx@help.co.za xxxb@help.co.za xxxc@help.co.za graham.goliath@gmail.com"
#Option1=" Run User Takeon Report" ;
#Option2=" Run User Expired Report" ;
#Option3=" Exit Program" ;

Displaymenu () {
clear
echo `DATE`
echo
echo "\t\t\t\t" $LOGO
echo
echo "\t\Select Option:"
echo
echo "\t\t\t [1] Run User Takeon Report "
echo "\t\t\t [2] Run User Expired Report "
echo "\t\t\t [3] Exit Prgram "
echo -n "Enter option then ENTER to continue:;"
}
PressEnter () {
echo Press Enter
read x
}
# A function for each of the menu picks


report_Takeon()
{
echo " Executing Run Takeon Report "
do_takeon()
echo " Enter email address then enter to continue: \c"
read email
if [ "$LIST" = xxxa@help.co.za ]
then
do_email ()
PressEnter
fi
}

report_Expired()
{
echo "Executing Run Expired Report"
do_expired()
echo " Enter email address then enter to continue: \c"
read email
if [ "$LIST" = xxxa@help.co.za ]
then
do_email ()
PressEnter
fi
}

#Function Exit()
#{
# echo "Exit Program"
# pressEnter
# ... perform certain actions
#}
do_takeon()
{
sqlplus -s mac/mac789@${WORKDIR}/takeondate.sql
}
do_expired()
{
sqlplus -s mac/mac789@${WORKDIR}/expirydate.sql
}
do_email()
{
echo "Emailing report now"
SUBJECT="User Takeon report"
TO=xxxa@help.co.za
(
cat $SPOOLFILE
) | /usr/local/bin/mutt -s "$SUBJECT" -a $SPOOLFILE $TO
}
while true
do
displaymenu
read answer
case $answer in
1) Run User Takeon Report ;;
2) Run User Expired Report ;;
3) break ;;
esac
done
clear

do_takeon()
{
sqlplus -s mac/mac789@${WORKDIR}/takeondate.sql
}
do_expired()
{
sqlplus -s mac/mac789@${WORKDIR}/expirydate.sql
}

is this correct? something looks amiss
 
At first glance, it looks OK.
Repalace Displaymenu with displaymenu in the definition of the function
Replace echo `DATE` with date
and call your functions in the while loop

Code:
while true
do 
    displaymenu
    read answer
    case $answer in
         1) do_takeon ;;
         2) do_expired ;;
         3) break ;;
    esac
done

Also,

You have a redundant duplicate function declaration for do_expired and do_takeon at the end of the script.
 
how do i get my email functio to send my spoolfile
do_email()
{
echo "Emailing report now"
SUBJECT="User Takeon report"
TO=xxxa@help.co.za
(
cat $SPOOLFILE
) | /usr/local/bin/mutt -s "$SUBJECT" -a $SPOOLFILE $TO
}
this is what my function looks like..
 
Is that not sending an email at all? Is it giving you an error message?

Do you want to attach your spoolfile to the email, or include it in the email body? At the moment you seem to be doing both.

Annihilannic.
 
Receiving email YES
My list file has a number of email addresses...but it sends it everyone...
I wanna enter a email address and it must be sent to that user who entered there email address..
how do i do it?
report_Takeon()
{
echo " Executing Run Takeon Report "
do_takeon
echo " Enter email address then enter to continue: \c"
echo
do_email
Pressenter
}
}
do_email()
{
echo "Emailing report now"
SUBJECT="User Takeon report"
TO=$LIST
(
cat $SPOOLFILE
) | /usr/local/bin/mutt -s "$SUBJECT" -a $SPOOLFILE $TO
}
These are the functions i have.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top