Asterisk command output in text file using crontab

Hi,

I have tried to run below command to get a output as text file using crontab, but it’s showing empty

*/1 * * * * asterisk -rx “sip show peers” | grep OK >> test.txt

and also saved this in one shell script as a.sh & gave 755 file pemission, tried below thing using crontab… same thing happened.

*/1 * * * * sh a.sh

#vi a.sh
!/bin/bash

system_page - A script to produce an system information HTML file

Constants

TITLE=“System Information for $HOSTNAME"
RIGHT_NOW=$(date +”%x %r %Z")
TIME_STAMP=“Updated on $RIGHT_NOW by $USER”

function show_uptime
{
# Temporary function stub
echo "Show_uptime"
w
}

function live_peers
{
echo "Live devices"
asterisk -rx “sip show peers” | grep -i OK
}

echo " **************************************************************************************************************************"
echo
echo " $(show_uptime)"
echo
echo " $(live_peers)“
echo
echo " ***************************************************************************************************************************”

output


Show_uptime
17:58:01 up 1:06, 2 users, load average: 0.98, 1.06, 0.99
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.10.1.30 16:54 1:03m 0.00s 0.00s rasterisk r
root pts/1 10.10.1.251 17:09 0.00s 0.09s 0.09s -bash

Live devices


~

Please help me to fix this issue.

Regards,
kalyanasundaram

Hi,

I tried you script on my server, it’s working fine.

make sure your asterisk running and up.

In addition, you can try that command directly on shell to test weather it’s working or not.

Sohaib Khan

Hi Khan,

Thanks for your reply, OK. if run the shell script as manually that is working, didn’t get output through text file whenever we will added to crontab.

Hi there,

Sorry for late reply…

try this it’s working on my crontab

*/1 * * * * /usr/sbin/asterisk -rx “sip show peers” | /bin/grep “OK” > /filname.txt

let me know if it works.

Hi,

it will work if installed using open source method (tar package), but I’ve installed using Asterisk now repos files. So that this command won’t work for me.

The only likely significant difference would be in under which user Asterisk runs. However, the file is created by cron, as root, so I don’t see how you would have a permissions problem.