Page 1 of 1

Bash script for SMS Server tools

Posted: Wednesday 27 January 2016 21:05
by Reinz
Iam trying to create a text file for processing in SMS server tools
but if the the script is fired via a switch in domoticz the created file is owned by "root" and the sms daemon "smsd" cannot acces the file.

for those who dont know sms server tools yet, its a sms gateway daemon which is monitoring a spool directory waiting for text files in /outgoing and moves them to /sent when everything worked

the script itself is pretty simple, but with my humble linux knowledge I would apprentice a good solution
Iam running 2.3530 domoticz raspberry image and the spool directory is in /home/pi/sms/ with its subdirectorys

Code: Select all

#!/bin/bash

today=`date '+%Y_%m_%d__%H_%M_%S'`;
sudo -u smsd echo "To: 436XXXXXXXXXXX
WAN is not reachable" >> "/home/pi/sms/outgoing/`date '+%Y_%m_%d__%H_%M_%S'`.txt"

Re: Bash script for SMS Server tools

Posted: Thursday 28 January 2016 16:23
by Reinz
After searching and puzzling found a solution, "sudu -u smsd" calls "tee" as another user (in this case sms deamon user) and writes the file.

Code: Select all

#!/bin/bash

timefile=`date '+%Y_%m_%d_%H_%M_%S'`;
timesms=`date '+%H:%M %d/%m'`;
echo -e "To: 436XXXXXXXXXXXXX\n\nWAN is not reachable. $timesms" | sudo -u smsd tee "/home/pi/sms/outgoing/$timefile.txt"
Just wasted some SMS to archive this ;)
Message report:
To: XXXXXXXXXXX
Modem: modem1
Sent: 16-01-28 16:10:41
Message_id: 36
IMSI: XXXXXXXXXXX

WAN is not reachable. 16:10 28/01