Running fwconsole reload from crontab results in error

Trying to have crontab run fwconsole reload once a day to apply settings changes. Tried running it from asterisk’s crontab and roots… no dice.

crontab command: */2 * * * * /root/ &>> /var/log/FreePBX_Modules

(running it every 2 min just for testing…)

gets the following error:

Reload Started

In Process.php line 239:

The command “runuser ‘asterisk’ -s ‘/bin/bash’ -c ‘cd /var/www/html/admin/m
odules/pm2/node && mkdir -p /home/asterisk/.pm2 && mkdir -p /var/www/html/a
dmin/modules/pm2/node/logs && export HOME=/home/asterisk && export PM2_HOME
=/home/asterisk/.pm2 && export ASTLOGDIR=/var/log/asterisk && export ASTVAR
LIBDIR=/var/lib/asterisk && export PATH=$HOME/.node/bin:$PATH && export NOD
E_PATH=$HOME/.node/lib/node_modules:$NODE_PATH && export MANPATH=$HOME/.nod
e/share/man:$MANPATH && /var/www/html/admin/modules/pm2/node/node_modules/p
m2/bin/pm2 jlist’” failed.

Exit Code: 127(Command not found)

Working directory: /root


Error Output:

sh: runuser: command not found

reload [–json] [–dry-run] [–skip-registry-checks] [–dont-reload-asterisk]

1 Like

I’m having the exact same error when trying to run fwconsole reload from a .sh script in crontab.

This is the .sh script we are trying to run:

/usr/sbin/fwconsole ma upgradeall > /dev/null 2>&1
/usr/sbin/fwconsole reload -q -n > /dev/null 2>&1

Any idea how we can make the command “runuser” work?

To start, use ‘crontab -u asterisk’ to have programs run as the Asterisk user. This avoids the entire ‘runuser’ complication.

For debugging purposes, take the 2>&1 off the end of the commands so you can see whatever the error output is.

Finally, try this crontab command instead:

/usr/sbin/fwconsole ma upgradeall && /usr/sbin/fwconsole reload

This way, the upgrade will run, then (if there are no errors) the reload will run. Getting rid of the output redirection won’t hurt since the output of these command is silence unless there’s an error, and no mail is sent if there’s no output.

BIG thanks for your guidance. The commands you mention run perfectly when executed from asterisk user crontab (crontab -u asterisk -e).
What I needed is to execute these commands on a .sh script using root user that changes based on our particular needs, so I followed your guidance that some fwconsole commands are required to be run as asterisk user, and finally the script worked with the following commands in the .sh script:

/usr/sbin/runuser -l asterisk -c ‘/usr/sbin/fwconsole ma upgradeall’ > /dev/null 2>&1
/usr/sbin/runuser -l asterisk -c ‘/usr/sbin/fwconsole reload’ > /dev/null 2>&1

ashcortech, you may try this approach and check if it works for you.

Best regards

1 Like

Thanks Nicolas!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.