I'm using apcupsd to respond to events on an APC UPS. The daemon effects responses by chaining BASH scripts. First it calls apccontrol (appending 4 arguments) which in turn calls a script specific to the event such as "onbattery". Users can only edit these 3rd level scripts.
I have edited my "onbattery" script to build up modular messages for emailing and broadcasting and all works well when I call the "onbattery" script directly & when it's called from the 2nd level apccontrol. However when the chain starts from the top level daemon all commands such as cat, echo and the redirects / appends seem to be ignored in the final "onbattery" script.
I understand from reading that redirection in spawned shells / scripts is an issue but not how to get around it. Can anyone help please.
the onbattery script is as follows
#!/bin/bash
echo -e "From: Admin@somewhere \nSubject: Server on battery $(date +%D_%T) \n\n" > email.txt
cat OnBattWarn.txt >> email.txt
cat email.txt | ssmtp remoteadmin@somewherelse
wall | email.txt
exit99
wall | email.txt
towall <email.txt
, and remove the line withexit99
. – ott-- Apr 10 '16 at 21:57