Fwconsole cron

Asterisk: 13.7.2


I am experimenting with fwconsole and cron, but seem to be running into a roadblock due to my lack of knowledge.

cron -l
0 5 * * * /usr/local/sbin/fwconsole restart

This should fire the restart command every morning at 5, but it is not happening. Is there anything that I am missing here? Is there a better way to schedule a reoccurring fwconsonle command?

Thanks for your help!

A better question would be “how do I make sure the cron program is running?”

I’ve seen this in other systems when the cron program crashes and doesn’t restart. Make sure that crond is running in your system.

That is a good question.

service crond status
crond (pid 1521) is running…

looks like its up and has been up during the run time.

Bump for this… Any one have any ideas?

so far I have tried:

0 5 * * * /usr/local/sbin/fwconsole restart
0 5 * * * /var/lib/asterisk/bin/fwconsole restart

I have also tried a shell script. It works when I manually run it, but when I set it as a cron (below), no luck.
0 5 * * * /root/restartfreepbx.cron


/usr/local/sbin/fwconsole restart


chmod +x
chmod +777

You should be able to find the results of the cron job attempt in the (root) user’s e-mail or in /var/log/cron or /var/log/syslog (depending on where your syslog daemon is set to send cron messages).

I’m not what those last two lines are supposed to do, but they are definitely not right. In fact, I’d say you’ve just destroyed the security of your system by giving everyone on the planet read, write, and execute access to your entire system.

In general, you should NOT be using chmod +777 ever. You don’t want the execute but turned on for everything in your system. Of course, chmod +x does pretty much exactly the same thing, so I’m certain that this is not going to do whatever it was you intended.

Apologies, to clarify, the ch mods were run specifically on /root/restartfreepbx.cron file and were not in the script/shell.

Going to /var/log/cron I do see the job.
Dec 29 05:00:01 xxx CROND[18681]: (root) CMD (/root/restartfreepbx.cron)

But when I check the asterisk uptime, I can see that it has been up for days.

Looking at the mail, I see some errors, but am not sure what the issue is.

Subject: Cron root@xxx /root/restartfreepbx.cron
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: LANG=en_US.UTF-8
X-Cron-Env: SHELL=/bin/sh
X-Cron-Env: HOME=/root
X-Cron-Env: PATH=/usr/bin:/bin
X-Cron-Env: LOGNAME=root
X-Cron-Env: USER=root
Message-Id: xxx@xxx
Date: Thu, 29 Dec 2016 05:00:01 -0800 (PST)

/usr/bin/env: pidof: No such file or directory
Asterisk not currently running
Running FreePBX shutdown…

sh: pidof: command not found
sh: pidof: command not found
Restapps daemon was not running
Stopping UCP Server
UCP Server Failed: sh: runuser: command not found

sh: pidof: command not found
XMPP Server was not running
Stopping Zulu Server
Zulu Server Failed: sh: runuser: command not found

Wanrouter: No valid Sangoma Hardware found, if you have no Sangoma cards this is OK
Stopping DAHDi for Digium Cards
DAHDi Stopped
Running VQPlus Hooks
Stopping Queue Callback Daemon
sh: pidof: command not found

it goes on

Your path for the cron job is different than the path for your shell.

1 Like

Summing this up…

That should be #!/bin/bash

Can you guide me how to find the cron log?
/var/log doesn’t have a /cron in it, or syslog. There is a /chrony, which is empty.

On FreePBX distro systems, cron logs to:

# ll /var/log/cron
-rw------- 1 root root 4957932 Feb 19 18:17 /var/log/cron

I have a similar problem to the OP.
My problem is that when the internet connection is lost temporarily overnight, the PJSIP trunk does not re-register until I do a core reload through the CLI. I want to automate this with a cron job to do core reload at 6am each day. To test this I set it up to reload every minute.

crontab -l gives this:

[root@freepbx ~]# crontab -l

          • core reload >/dev/null 2>&1

In the cron file I see this:

Feb 21 05:22:01 freepbx crond[950]: (asterisk) RELOAD (/var/spool/cron/asterisk)
Feb 21 05:22:01 freepbx CROND[26633]: (asterisk) CMD ([ -x /var/lib/asterisk/bin/schedtc.php ] && /var/lib/asteri$
Feb 21 05:22:01 freepbx CROND[26634]: (root) CMD (core reload >/dev/null 2>&1)
Feb 21 05:22:01 freepbx CROND[26637]: (asterisk) CMD ([ -x /var/www/html/admin/modules/dashboard/scheduler.php ] $
Feb 21 05:22:01 freepbx CROND[26638]: (asterisk) CMD (/var/lib/asterisk/bin/pagepro-scheduler.php 2>&1 >/dev/null)
Feb 21 05:22:01 freepbx crontab[26661]: (asterisk) LIST (asterisk)
Feb 21 05:22:01 freepbx crontab[26663]: (asterisk) LIST (asterisk)
Feb 21 05:22:01 freepbx crontab[26664]: (asterisk) REPLACE (asterisk)
Feb 21 05:22:01 freepbx crontab[26666]: (asterisk) LIST (asterisk)
Feb 21 05:22:01 freepbx crontab[26668]: (asterisk) LIST (asterisk)

and so on

BUT in the Asterisk log in FreePBX I am not seeing it doing a reload like I see when I do core reload throught the CLI on the GUI.

Is it doing a reload or not?? (The output was unchanged with #!/bin/bash or with #!/bin/sh in the cron command file)

What are you hoping this is supposed to do?

‘core reload’ is an Asterisk CLI command, not a Unix command…

Alternatively run fwconsole reload

1 Like

your cron should looks like this

* * * * * /usr/sbin/asterisk -x "core reload"
1 Like

Is it a valid entry in asterisk crontab, to say:
0 3 * * * /usr/sbin/fwconsole firewall stop > /dev/null 2>&1
5 3 * * * /usr/sbin/fwconsole firewall start > /dev/null 2>&1
What happens if firewall is not running at 3 o clock? Any error message expected?
Do I need a fwconsole before firewall? or is ist “fwconsole firewall stop” including quotation marks?

editing asterisk crontab with
EDITOR=nano crontab -u asterisk -e

Problem: my firewall is disabled automatically every morning. Maybe logrotation breaks it.


what do we ve to put in order to do a fwconsole restart, using cron in FreePBX 15 ?
i am confused ?

As the asterisk user or root user. You would need to test and verify which works for you.

set your time approriately…

sudo -u asterisk crontab -e
sudo -u root crontab -e
0 * * * * /usr/sbin/fwconsole restart > /dev/null 2>&1