I need to start off by saying that I am not much of a programmer and know enough to cause lots of trouble.
I've been writing this script to decrypt an XML feed, then parse the feed into a database. The script is executed from cron.
#!/bin/sh
PGPPATH=/path/to/directory
echo "pgp directory $PGPPATH"
if [ -f ${PGPPATH}/*.pgp ];
then
for FILE in ${PGPPATH}/*.pgp;
do
echo "decrypting $FILE"
/bin/echo mypassword | /usr/bin/gpg --no-tty --batch --passphrase-fd 0 --quiet --output ${FILE%.pgp}.xml --decrypt $FILE
echo "parsing xml"
/usr/bin/java -jar /root/XmlParse/XmlParser.jar "${FILE%.pgp}.xml" "jdbc:mysql://127.0.0.1/mydb" "admin" "mypassword"
echo "moving $FILE to ${PGPPATH}/feed_archive"
mv $FILE ${PGPPATH}/feed_archive
echo "moved $FILE to ${PGPPATH}/feed_archive";
mv ${PGPPATH}/*.xml ${PGPPATH}/xml
echo "mv ${PGPPATH}/*.xml ${PGPPATH}/xml";
done
else
echo "pgp files do not exists"
fi
The results are stored in a log. Here is an example of the log entry:
pgp directory /path/to/directory
decrypting /path/to/directory/IL_200902040703.pgp
parsing xml
working...
completed!
moving /path/to/directory/IL_200902040703.pgp to /path/to/directory/feed_archive
moved /path/to/directory/IL_200902040703.pgp to /path/to/directory/feed_archive
mv /path/to/directory/*.xml /path/to/directory/xml
Occasionally, the XmlParser.jar fails. I know it fails because the log above is missing the "completed!". When I run the script form the command line, I can see a java error stack. What I need is to have an email triggered containing the java error when the XmlParser.jar fails. Thanks in advance for any suggestions.