Crontab not connecting on schedule

All, I was running allstar, dvswitch, allmon in the Amazon Cloud for a year. All worked as it should. Because Amazon started billing we moved the entire cloud to Virmach which in the overall picture will be cheaper. When doing so the crontab stopped connecting. Now it may be a VIRMACH isuse but at this point I think I am just doing something wrong. The rented VM did not at first know what time zone or time it was but I fixed that. Now it just does not run the cron as it should. My example below:

@reboot sudo timedatectl set-timezone America/Detroit
01 03 * * * cd /var/www/html/allmon2; ./astdb.php
00 04 * * 1-5 /usr/sbin/asterisk -rx “rpt fun 50964 *329789”
00 07 * * 1-5 /usr/sbin/asterisk -rx “rpt fun 50964 *129789”

The system never connects but the system log does show it running when it should. Does my Cron look correct? I am only a HAMVOIP user until this project and the OS is a little different.

I think it is running crontab without ‘user’ set.

Here is one of my entries.

27 13 * * * root cd /var/www/html/allmon; ./astdb.php

As a rule of thumb, I always execute with the full path included.
Format =

m h dom mon dow user command

Thanks, I updated my cron and will see if it runs in the morning.

¡¡¡

Darrell Black

(517) 917-2226
GigaHacker@gmail.com
http://www.linkedin.com/in/darrellblack

73 de W8DSB
“In God we trust, all others we monitor”

GMRS WRDE739
ALLSTAR 50964
DMR 310195

Adding root in did not fix the issue. It apears this version used root as part of the command and not as a user. The log file shows that the command

00 04 * * 1-5 /usr/sbin/asterisk -rx “rpt fun 50964 *329789”

is already being run by root but its not really running.

Is my path correct?

Let’s get a little more background.
Is the os the default debian install ?

crontab logs to syslog, but if you have not configured mta, it will not log crontab events.
It would mail the owner of crontab function.

Also, if you are using or have used a windows editor to edit crontab, it will corrupt it.
Let me know if that is the case.
While you can get away with it most times in asterisk .conf files, not with system files.

This is used in VIRMACH site. I started with “Linux Ubuntu 16.04 Server X86 64 Minimal Latest - 23.94.138.56” as a base load. This is the same version I was running at Amazon cloud before moving to VIRMACH (cheaper).

Service running by me

Allstar
Allmon II
Dvswitch
HBllink

All services are running ok with no issues. I just cannot get a CRONTAB to run. I just installed MTA last night and looked at logs from overnight and this is what I see.

Dec 10 03:01:01 W8LRK CRON[26698]: (root) CMD (cd /var/www/html/allmon2; ./astdb.php)
Dec 10 03:01:03 W8LRK postfix/pickup[24191]: 098A91E5AE: uid=0 from=
Dec 10 03:01:03 W8LRK postfix/cleanup[26702]: 098A91E5AE: message-id=20201210080103.098A91E5AE@W8LRK
Dec 10 03:01:03 W8LRK postfix/qmgr[869]: 098A91E5AE: from=root@W8LRK, size=551, nrcpt=1 (queue active)
Dec 10 03:01:03 W8LRK postfix/local[26704]: 098A91E5AE: to=root@W8LRK, orig_to=, relay=local, delay=0.1, delays=0.04/0.04/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
Dec 10 03:01:03 W8LRK postfix/qmgr[869]: 098A91E5AE: removed

Dec 10 04:00:01 W8LRK CRON[27819]: (root) CMD (/usr/sbin/asterisk -rx “rpt fun 50964 *329789”)

I see no errors. Is there are better set of logs somewhere?

Try it at the cli to help sort out what’s going on. Can you cd into /var/www/html/allmon and then ./astdb.php?

I do not believe the syslog will log cron job output.

So, if you make your crontab job a shell script, you can pipe the output to a file.

59 23 * * * /etc/asterisk/cronjobs//shellscript.sh > /var/log/mycronlog.txt

Perhaps that can be done without the shell script but I have never tried it.
If you try it, make sure you set owner/permissions of the script file.

Just trying to think of options.
But as Tim said, you should verify you can run these from a command line and see what is up just as a first step if you have not already.

Here’s how I accomplish this on my system with scripts. I use permanent links incase it becomes disconnected, it will reestablish the link automatically.

Here’s one example from my crontab:

#Connect to Texas X-Reflector 497330 at 7:35am
35 7 * * * /etc/asterisk/local/connect.sh 525240 497330 > /dev/null 2>&1

#Disconnect from Texas X-Reflector at 9:00am
1 9 * * * /etc/asterisk/local/disconnect.sh 525240 497330 > /dev/null 2>&1

Here are the scripts, remember that you have to make the executable:
first one is the connect.sh script:

#!/bin/bash
#Connect Script for Crontab
#Made by K6IAN 11/11/2020

#Example usage in crontab
#00 09 * * * /etc/asterisk/local/connect.sh 40000 40001
#This says connect at 0900 (9AM - Minutes first then hours) node 40000
#to node 40001
#This can also be used on the command line

#Local playback connect message
/usr/sbin/asterisk -rx “rpt localplay $1 /etc/asterisk/local/conf_connect”

sleep 1

#Connect permanent link
/usr/sbin/asterisk -rx “rpt cmd $1 ilink 13 $2”

the second one is disconnect.sh script:

#!/bin/bash
#Disconnect Script for Crontab
#Made by K6IAN 11/11/2020

#Example usage in crontab
#00 09 * * * /etc/asterisk/local/disconnect.sh 40000 40001
#This says disconnect at 0900 (9AM - Minutes first then hours) node 40000
#to node 40001
#This can also be used on the command line

#Disconnect permanent link
/usr/sbin/asterisk -rx “rpt cmd $1 ilink 11 $2”

sleep 1

#Local playback disconnect message
/usr/sbin/asterisk -rx “rpt localplay $1 /etc/asterisk/local/conf_disconnect”

I have two audio files that I created “conf_connect.ulaw” and “conf_disconnect.ulaw” that you can see that the scripts call up and play locally. I created those by running these following commands:

cat /var/lib/asterisk/sounds/conference.ulaw /var/lib/asterisk/sounds/connected.ulaw > /etc/asterisk/local/conf_connect.ulaw

cat /var/lib/asterisk/sounds/conference.ulaw /var/lib/asterisk/sounds/disconnected.ulaw > /etc/asterisk/local/conf_disconnect.ulaw

I can’t take the credit fully for all of this, as I usually browse the forums and look at what others are doing and then try it another way to be different… lol

-Ian K6IAN

1 Like

Just a quick follow up:

@reboot timedatectl set-timezone America/Detroit
01 03 * * * cd /var/www/html/allmon2; ./astdb.php
00 04 * * 1-5 /usr/sbin/asterisk -rx “rpt fun 50964 *329789”
00 07 * * 1-5 /usr/sbin/asterisk -rx “rpt fun 50964 *129789”

This now works. I am not sure why it was not working but I deleted the crontab file and created another and it worked as it should have. Adding ‘root’ in does not seem to work correctly for this version of linux.

It likely had a non visible illegal character in the file. Similar to what happens when you edit the file with a windows editor cr/lf.

For future reference, You can use notepad+++ and some other editors to show all chars in the file.