Serpien
New Around Here
I have an openvpn-event script running which should send an email message. I used logging commands in the script to validate that indeed the script is being called and is running to completion.
HOWEVER - and this is weird - the sendmail portion of the code only works if the script is called directly from the shell. In that case, I can see all the terminal output from sendmail and the email is sent. When run by the router as part of the openvpn-event, no email is sent. However, all logging messages are present in the router logs, right down to the last one.
Maybe a permissions issue with calling openssl and./or sendmail?
Any thoughts most appreciated
HOWEVER - and this is weird - the sendmail portion of the code only works if the script is called directly from the shell. In that case, I can see all the terminal output from sendmail and the email is sent. When run by the router as part of the openvpn-event, no email is sent. However, all logging messages are present in the router logs, right down to the last one.
Maybe a permissions issue with calling openssl and./or sendmail?
Any thoughts most appreciated
Bash:
#!/bin/sh
echo "Starting script openvpn-event" | logger -t "openvpn-event"
FROM="myacct@gmail.com"
AUTH="myacct@gmail.com"
PASS="myapppassword"
FROMNAME="Asus Router"
TO="myacct@hotmail.com"
echo "script_type=$script_type"
echo "script_type=$script_type" | logger -t "openvpn-event"
echo "Calling ntpclient" | logger -t "openvpn-event"
ntpclient -h pool.ntp.org -s &> /dev/null
sleep 5
echo "Writing temp email file" | logger -t "openvpn-event"
echo "Subject: Router OpenVPN Event" >/tmp/mail.txt
echo "From: \"$FROMNAME\"<$FROM>" >>/tmp/mail.txt
echo "Date: $(date -R)" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "Event: $script_type" >>/tmp/mail.txt
echo "" >>/tmp/mail.txt
echo "Calling sendmail" | logger -t "openvpn-event"
cat /tmp/mail.txt | /usr/sbin/sendmail \
-H "exec openssl s_client -quiet \
-starttls smtp \
-connect smtp.gmail.com:587 \
-no_ssl3 -no_tls1" \
-f "$FROM" -au"$AUTH" -ap"$PASS" "$TO" -v
echo "Deleting temp email file" | logger -t "openvpn-event"
rm /tmp/mail.txt
echo "Completed script openvpn-event" | logger -t "openvpn-event"