Python Forum

Full Version: Script to send data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

I am newbie to Unix and Shell script and Python. Can you please help me to write a Python script.

Below is my requirement.

1.Send in email every 15 minutes from 12 to 3:30 PM. It has to create a backup files from 12- 3:30

E-mail should only be sent ONLY when below Query have data return else need to raise an exception " there is no data"

Query : SELECT * from EMP where DEPT = 87;

2. Email format:
To: xyz
From: abc
Email Subject:
Email content: <data return from below query>

Thanks.

I have written a code in UNIX. Anyways that code is not working. Below is my code.Please look into the code and hemp me to write it in both Shell and Python.
</code>
</code>
FILE="EMP_DETAILS.txt"
#FILE="EMP_DETAILS.$(date +%F_%R).txt"
#touch $FILE

echo $ORACLE_HOME/bin/sqlplus
echo "======== START ============="

#$ORACLE_HOME/bin/sqlplus -s scott/tiger@XE <<EOF
RESULT=`$ORACLE_HOME/bin/sqlplus -silent ${DB_USER}/${DB_DECRYPTED_PASSWORD}@${DB_CONNECTION_STRING} <<ENDA

set pagesize 0 feedback off verify off heading off echo off
column last_business_date format date
SELECT * from EMP where DEPT = 87;

exit;
ENDA`

echo $RESULT > $FILE
#sed -i 's/#^/\n/g' $FILE
sed '/#^/G' $FILE
echo "======== END ============="


## READ AND WRITE THE FILE AND TOOK THE BACKUP
#
#FILE1="EMP_DETAILS.$(date +%F_%R).txt"
#{
# while IFS= read -r line
#do
# shnfix "$line"
# done < "$FILE1"
#} > "emp.backup.$(date +%F_%R).txt"

##this will fetch the number of lines in the file
#wc -l $FILE1
#if [wc -gt 0]; then
mail -s "!!! WARNING File" << $EMP_DETAILS.txt
echo "The IDL processing has been completed for Business date $BUSINESS_DATE." | mail -s "IDL Processing Status $env" "[email protected]" -- -r "robin@gmail";
#fi
</code>
just full quote of OP