Bash script for SMS Server tools

Post Reply
Reinz
Posts: 6
Joined: Wednesday 27 May 2015 11:29
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Austria
Contact:

Bash script for SMS Server tools

Post by Reinz » Wednesday 27 January 2016 22:05

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"

Reinz
Posts: 6
Joined: Wednesday 27 May 2015 11:29
Target OS: Raspberry Pi
Domoticz version: 3.5877
Location: Austria
Contact:

Re: Bash script for SMS Server tools

Post by Reinz » Thursday 28 January 2016 17:23

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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest