How to run a PowerShell file during boot as root on Asterisk?
-1
votes
1
answer
277
views
On Asterisk boot/reboot I want a PowerShell file to be executed.
I have created a *.ps1* file on
/var/spool/
which is supposed to copy new files from an asterisk directory and transfer them to an Azure storage container. This file is supposed to get each last recording file and transfer it to the Azure's container. When I run the command manually on root, it works. This is an output of a recording file successfully uploaded on Azure's container.
Name BlobType Length ContentType L
a
s
t
M
o
d
i
f
i
e
d
---- -------- ------ ----------- -
out-067…9249.0.wav BlockBlob 44 application/octet-stream 2
uploaded!
To get every new recordings it has to be run endlessly ( check for new files every one minute). To do this I have used a cycle do/while($true), with a command60
inside it.
In case of any system reboot or power outage I want this file (ps1) to start running again after OS boot.
To do this I tried adding the command /var/spool/transferrecordings.ps1
on **/etc/rc.local** to make it work in case of a system reboot. I edited this directory with /etc/rc.local
as below:
This is the script I'm using in the directory /etc/rc.local
.
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
pwsh /var/spool/transferrecordings.ps1
exit 0
But nothing seems to happen on server boot.
I tried editing crontab with -e
by adding command:
@reboot pwsh /var/spool/transferrecordings.ps1
. Nothing again.
I'm using Sangoma Linux (CentOS 3.10.0).
Any suggestions please?
Asked by admiri
(101 rep)
Apr 26, 2021, 11:45 AM
Last activity: Apr 29, 2021, 02:18 PM
Last activity: Apr 29, 2021, 02:18 PM