Redirecting asterisk CLI to a file

Can you please assist me in writing a script to redirect the output of asterisk -vvvr to a file( I used asterisk -vvvr > filename). With normal commands like tail, I am able to do it. But in the case of asterisk, once the process is started, I am not able to stop it from the script.



See /var/log/asterisk/messages and /etc/asterisk/logger.conf


Thank you for your reply. The /var/log/asterisk/messages contains the entire log. I just wanted to split it say daily or say upto 5 mb size. The file name should contain time stamp. I am copying my script below.


now=“Log_date +%F_%T

touch $final

rasterisk -vvvvv >> $final &

usage=du -h $final | awk '{ print $1 }' | sed s'/.$//' | sed s'/.$//' | sed s'/.$//'

apid=pidof rasterisk

if [ $usage -eq “4” ];
echo "boom boom"
kill -9 $apid
echo "completed"
exit 0

Never use kill -9 in a context like this. It is a last resort, not a first choice.

The correct way of doing this is to move the /var/log/asterisk/full file then use rasterisk to send a logger command to asterisk. Details are left to the reader.

Have a look through the logger commands. There may be ones that make this even easier.

Wouldn’t it be more efficient just to parse the existing log file from Asterisk and storing the parsed output in separate files? I think doing a couple of grep/sed/awk commands would not be so hard … And you can make this parser script run as a cronjob that is excecuted every night.

I don’t think he’s even trying to parse it. I think he’s just trying to do a log roll, based on log size. He only needs a move, not a copy.

There’s a script in the contrib directory that performs log rotation, to install it do:

make install-logrotate

from the Asterisk source directory.


Thanks for all your replies. I am a newbie to asterisk. So I don’t have the complete picture. What I just tried was to split the logs into smaller files say 5 MB so that I can store it in a safe location for future reference. I think What dejanst suggested is a nice idea. I will try that definitely

I’d strongly suggest looking at the contrib script, and if it doesn’t use logrotate, doing man logrotate. You will almost certainly get a cleaner, and more efficient, solution.

Hey that seems to be perfect. Thanks David. i will try this today itself. Thanks a lot for the info

Hey I tried installing logrotate using make install-logrotate. But I am getting the following error

make: No rule to make target `install-logrotate’. Stop.

Can you please help me. I am using asterisk

Ah, that’s not part of the Makefile until 1.6.0.


[quote=“malcolmd”]Ah, that’s not part of the Makefile until 1.6.0.


Ok thanks. It was already installed. I did some configurations for daily rotate with rotate count 5.
/var/log/asterisk/messages {
rotate 5
size 3000k

Do I have to add a cronjob in order to get it work? Size of my /var/log/messages crossed 3 mb. Still asterisk is writing to the same file. Did I forget some step