Run a cron job to get the user agent list and send an email alert

configuration
Tags: #<Tag:0x00007f702aa7adb8>

(FAK) #1

Hi all,

I want to run the below command to get user agent list and send an email alert using cron job.

for ext in $(rasterisk -x 'sip show peers'|egrep "^[0-9]*/[0-9]*.*OK"|sed 's/^\([0-9]*\).*/\1/');do echo -ne "$ext\t";rasterisk -x "sip show peer $ext"|grep Useragent|cut -d ":" -f2;done

how this can be acheived.


#2

That looks familiar :slight_smile:

if you don’t have mail then install mailutils . cron uses /bin/sh whose echo can’t do -ne so a bash script would look much like

#!/usr/env/ bash
for ext in $(/usr/sbin/rasterisk -x 'sip show peers'|egrep "^[0-9]*/[0-9]*.*OK"|sed 's/^\([0-9]*\).*/\1/')
do echo -ne "$ext\t";/usr/sbin/rasterisk -x "sip show peer $ext"|grep Useragent|cut -d ":" -f2
done|mail -s "my Stuff" faisal@khan.com

and the cronjob as root
0 0 * * * /path/to/your/script.sh


(FAK) #3

Thanks dicko… :slight_smile:

where should I create this file ?


#4

anywhere your crontab user can read and execute it from