It does, yes.
I am in your debt, Sir. Thank you!
---------- Post updated at 11:52 AM ---------- Previous update was at 10:05 AM ----------
Can I pick your brains a bit more?
OK, so I got that script to run, and it returns '0' - which is what it should return when everything's OK.
If it returns a non-zero result, I have to run the same SQL request, only ... well, this (note that the variable names are slightly different!) ..
orderStatus=$(/usr/bin/mysql -N -B mydatabase -e 'SELECT ordernumber FROM orders as o JOIN users as u ON o.userthing=u.package
WHERE o.table BETWEEN (now() - INTERVAL 1 day) AND
now() - INTERVAL 25 hour) AND o.p_stateorder=1 AND
u.name != "The Site" AND u.p_username NOT LIKE "myAddress@mailserver.com";')
If there is one result to that query, then that's fine. But what if there are several? I tried an array in a bash shell - which is something I've never done, so a lot of googling was required, and came up with .. OK, here is the entire script..
## get date
today=`date +"%d-%m-%Y-%H-%S"`
if [ -f /root/extrac.txt ]; then
/bin/rm /root/extrac.txt
fi
#### check orders
result=$(/usr/bin/mysql -N -B mydatabase -e 'SELECT COUNT(*)
FROM orders as o JOIN users as u ON o.userthing=u.package
WHERE o.table BETWEEN (now() - INTERVAL 1 day) AND
now() - INTERVAL 25 hour) AND o.p_stateorder=1 AND
u.name != "The Site" AND u.p_username NOT LIKE "myAddress@mailserver.com";')
/bin/echo "" > /root/extrac.txt
/bin/echo "The date is $today" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "We have verified the number of orders still in 'submitted' state" >> /root/extrac.txt
/bin/echo "after four hours." >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
if [ $orderStatus != "0" ]; then
/bin/echo "" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "The number of orders in this state is not zero." >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "As such, the web order numbers are echoed below : " >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
orderStatus=$(/usr/bin/mysql -N -B mydatabase -e 'SELECT ordernumber FROM orders as o JOIN users as u ON o.userthing=u.package
WHERE o.table BETWEEN (now() - INTERVAL 1 day) AND
now() - INTERVAL 25 hour) AND o.p_stateorder=1 AND
u.name != "The Site" AND u.p_username NOT LIKE "myAddress@mailserver.com";')
while [ $result ]
do
/bin/echo "" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "$result" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
done
exit 0
fi
/bin/echo "" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "The number of orders is zero, and as such, no web order numbers are available" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "Any questions, please e-mail me@mymailaddress.com" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
/bin/echo "-------------------------------------------------------------" >> /root/extrac.txt
/bin/echo "" >> /root/extrac.txt
And then I cat the file and pipe it to mail.
For the moment, that always returns zero, but I'm not entirely sure that the day '$result' is non-zero, that I'm going to get an array.
I could probably do this in PhP, but it's not on the server, and it's a production box, so I can't install it.