I need to fetch the results of different time ranges and email the results, but i am having trouble with the email part of the script,
how can i send an email with both results? (15min range and cumulative results) here's the line :
echo -e "Enter Start hour : xx:00:00"#ask user to input base time
read tI
echo "Select minute range, Enter 1 to 4"#ask user to select minute range
echo -e "\t1) XX:15:00 \n\t2) XX:15-30 | XX:30 \n\t3) XX:30-45 | xx:45 \n\t4) XX:45-00 | 1hour"
read NUM
if [ "$NUM" == "1" ] ; then
for Time in "$tI:(0[0-9]|1[0-4]:[0-5][0-9]|$tI:15" ; do #time grep c/o of Caleb, thanks!
mail
done
elif [ "$NUM" -eq "2" ] ; then
for Time in "$tI:(1[5-9]|2[0-9]:[0-5][0-9]|$tI:30)" "$tI:([0-2][0-9]:[0-5][0-9]|$tI:30)" ; do # 2nd time was commulative
mail
done
elif [ $NUM -eq 3 ] ; then
for Time in "$tI:(3[0-9]|4[0-4]:[0-5][0-9]|$tI:45)" "$tI:([0-3][0-9]||4[0-4]:[0-5][0-9]|$tI:45)" ; do
mail
done
elif [ $NUM -eq 4 ] ; then
tI=${tI#${tI%%[!0]*}}
newTime=$((tI + 1))
sTime=`printf '%02d\n' "$tI"`
fTime=`printf '%02d\n' "$newTime"` # thanks to Gilles and Mark and geekosaur
for Time in "$sTime:(4[5-9]|5[0-9]:[0-5][0-9]|$fTime:00)" "$sTime:([0-5][0-9]|[0-5][0-9]|$fTime:00)" ; do
mail
done
else
exit 1
fi
exit 1
function Count()
{
textfile="/some/path/to/text.txt"
time="$1"
C=0
echo " " > $textfile
for ((d=0; d<12; d++))
do
dec110=`egrep "$GivenDate $time" * | grep -c "$var .. ${DECLINE[$d]}" | awk '{SUM += $1} END { print SUM }'`
COUNT[$C]="$SUMdec"
((C++))
.... so on and so fort
echo -e "tons of to be echoed above /n end of the results to be emailed" >> $emessage
}
NOW HERE'S MY PROBLEM: ive tried several atempts but non of them seems to be working as they should.
function mail()
{
echo "declarations above of this | start of message" > $emessage
for ((t=0; t<2; t++)) do
Count "$Time"
done
/bin/mail -s "$SUBJECT" "$EMAIL" < $emessage
echo -e "Email Sent!\n\n"
cat $emessage
}
-- this will send out 1 email but only shows the result of the first grep,
function mail()
{
echo "Hi Team," > $emessage
Count "$Time"
/bin/mail -s "$SUBJECT" "$EMAIL" < $emessage
echo -e "Email Sent! \n\n"
cat $emessage
}
-- would send out 2 separate email if i choose option 2-4.
Note : without the email part this script is working fine.
exit 1
followed by more code, random-looking indentation, omitted parts, …). Read how to ask (follow the links on the right, as well). Don't throw us a wall of code, you need to meet us halfway and put up a coherent question. – Gilles Jul 10 '11 at 13:05