Saytime ASL3 script

I used kd5fmu script to install the time and weather for ASL3 but encountering a problem when executing DTMF manually. I have changed the 81 = cmd, perl /usr/local/sbin/saytime.pl zzzzz nnnnn.
the hourly works fine from crontab but when i execute manually, it plays the time from when the last crontab played and not the current time.

I wonder if anyone else has had this problem?

John

You may need to grant the asterisk user rights to the tmp directory. Start a couple of SSH sessions and in one have the Asterisk CLI running. In the other run the commands. Note any erros in the CLI.

I am using an HT so I opened the cli and dtmf *81 and the cli played the file but wrong time. Did not see any errors.
– Remote UNIX connection
– Remote UNIX connection disconnected
– Hungup ‘DAHDI/pseudo-1976644963’
– <DAHDI/pseudo-187479560> Playing ‘/tmp/current-time.gsm’ (language ‘en’)
– Hungup ‘DAHDI/pseudo-187479560’

didn’t run from cli as I’m not that experienced with cli commands.

I suspect it is a permission problem. The user trying to create the current-time.gsm doesn’t have permssions to /tmp. You could try running the following;
sudo chmod -R a+rwx /tmp
Then try the command again.

One should not do this. This is insecure and may break applications.

after running the command the cli was continously scrolling and I had to pull the power on the Pi and reboot. When it rebooted, this is the error message I received when dtmf w HT then at 9am received the same message when played from cron. Both no audio the cron keyed up with no audio. I tried DTMF w HT again it says just mostly cloudy. I will try running the installation of script again and report back. Thank you for your help

– Hungup ‘DAHDI/pseudo-1304732984’
[2025-03-08 08:56:22.927] WARNING[1497]: file.c:611 filehelper: File /tmp/current-time.gsm detected to have zero size.
– Hungup ‘DAHDI/pseudo-33076475’
– Remote UNIX connection
– Remote UNIX connection disconnected
[2025-03-08 09:00:03.442] WARNING[1691]: file.c:611 filehelper: File /tmp/current-time.gsm detected to have zero size.
– Hungup ‘DAHDI/pseudo-2124711709’

fortunately, I had backed up, so I just ran the backup and it’s playing the correct time/temp/weather announcements from crontab hourly.

I reverted the 81 in rpt conf back to status 12 so it gives me the current time without the temp or weather conditions.

I even tried using the crontab entry in 81, but it still gave me a previous time.

File /tmp/current-time.gsm detected to have zero size

From the command prompt can you type ‘whoami’ without the quotes.

There is a problem with how the scripts are setup and ownership.
Running the script as root prevents asterisk from accessing the files.
Run these commands:
sudo chown asterisk:asterisk -R /usr/local/share/asterisk
sudo rm /tmp/condition.gsm
sudo rm /tmp/temperature

Then make sure to only run the script as asterisk or with sudo -u asterisk saytime.pl xxx xx
aka if your using a cron, make sure it’s in the asterisk user.

I went back and reburned the image and started fresh. I ran the 3 lines then edited the rpt.conf file and put this in place of orig 81 :

;81 = status,12 ; Give Time of Day (local only)
81 = cmd, perl /usr/local/sbin/saytime.pl 44512 27915

still giving wrong time when executing *81 dtmf from HT. Not a big deal but makes me mad it won’t play correct time temp and weather on demand.

I’ve spent sleepless nights putting this together and this is the last thing that I can’t make work. Ughhh

1 Like

I just ran this from k1if@node27915:~ $ sudo -u asterisk saytime.pl 44512 27915
48°F, 9°C / Sunny
rm: cannot remove ‘/tmp/temperature’: Operation not permitted
rm: cannot remove ‘/tmp/condition.gsm’: Operation not permitted
/usr/local/sbin/weather.sh: line 150: /tmp/temperature: Permission denied
/usr/local/sbin/weather.sh: line 189: /tmp/condition.gsm: Permission denied
sh: 1: cannot create /tmp/current-time.gsm: Permission denied
Unable to access the running directory (Permission denied). Changing to ‘/’ for compatibility.
Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)

Are the files owned by asterisk ?
OR
not sure how that might work since you are executing python scripts.
Something to look at. Ownership of files and under what user is the python executing.

Does the following work or do you get an error. Permission denied etc.

sudo -u asterisk mkdir /tmp/test

If it doesn’t work then the user ‘asterisk’ does not have sufficient permissions to the /tmp directory.

Your /tmp/ directory should have permission 1777 - i.e. chmod 1777 /tmp.

# ls -ld /tmp
drwxrwxrwt 10 root root 4096 Mar  9 14:52 /tmp

The script is automatically setting up a cronjob under the root user.
Once the cronjob runs, it creates (and leaves) temporary files that belong to root. When you try to run the command from inside asterisk it can not over write the root owned temp files and it plays the old stuff.

You need to remove the cronjob using sudo crontab -e, then delete any of the files in the /tmp/ dir that root owns.
After that, as long as you only run the script as the asterisk user (either from asterisk with the commands, or sudo -u asterisk at the command line) you should be fine.

1 Like

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