[Asterisk-Users] Numbered Voicemails even with delete option!

David Waugh David.Waugh at eicon.com
Mon Mar 20 04:49:03 MST 2006



Thanks Bret for the input. Your solution seems a lot neater=)
I had problems with "globbing" I think it is called.

I kept getting files name being created called "msg*.txt" which caused
me problems later.
I think your way removes this.

The reason I was doing this was for testing purposes. I was making many
thousands of calls to the asterisk server as a stress test, and then
emailing them across. - Nothing really useful in the real world.


-----Original Message-----
From: asterisk-users-bounces at lists.digium.com
[mailto:asterisk-users-bounces at lists.digium.com] On Behalf Of trixter
aka Bret McDanel
Sent: 20 March 2006 10:21
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [Asterisk-Users] Numbered Voicemails even with delete
option!

On Mon, 2006-03-20 at 09:32 +0000, David Waugh wrote:
> NOTE: This is my first shell script so I'm sure it can be improved!
> 

noted, in that spirit see notes below ...


> *******************************************************
> [root at centos INBOX]# more /etc/asterisk/voicemail-clean 
> 
> cd /var/spool/asterisk/voicemail/default/1234/INBOX
> 
this appears to be redundant since you specify the full path in the find
below ...  It doesnt hurt anything though.

> #Only move files that are not currently in use that are over 3 bytes
> find /var/spool/asterisk/voicemail/default/1234/INBOX -mmin +1 -and
> -size +3c -exec cp {}
>  /tmp \;
> 

why cp em to /tmp?  Seems a waste given what you do with the files
in /tmp later...


> #replace contents of these files with 0 to save space
> 
> #find /tmp -name 'msg*.*' -and -type f -exec echo 0 >{} \;
> 
> for i in /tmp/msg*.gsm
> do
>   echo 0 >$i
> done
> 
> for i in /tmp/msg*.txt
> do
>   echo 0 >$i
> done
> 
> if [ -f /tmp/msg\*.txt ]
> then
>   rm -f msg\\*.txt
>   rm -f msg\\*.gsm
> fi
> 

after putting a 0\n in each file you then rm it without doing anything
else ...  Why waste the time copying them earlier, then making the files
contain only 0\n just to rm em?


> #delete any wav or WAV files
> rm -f /tmp/*.wav
> rm -f /tmp/*.WAV
> 
> #Delete any files that are not currently being used
> find /var/spool/asterisk/voicemail/default/1234/INBOX -mmin +1 -and
> -type f -and -size +3
> c -exec rm -f {} \;
> 
> #Copy our changed files back to the directory to fool asterisk!
> cp -f /tmp/msg*.* /var/spool/asterisk/voicemail/default/1234/INBOX/
> rm -rf /tmp/msg*.*
But if those exited they were deleted above ...


> #Cleanup
> rm -f /var/spool/asterisk/voicemail/default/1234/INBOX/msg\*.gsm
> rm -f /var/spool/asterisk/voicemail/default/1234/INBOX/msg\*.txt
> 

If by some chance they were able to survive the previous copies,
deletes, then copied again, you make sure they dont survive any
further :)


how about this, would it do what you want (note I am basically using
what you started out with)  It also makes em 0 bytes instead of 2 :)
And it works on more than one user at a time, although that may not be
desired.

The size +3c may need to be altered since it wont have 2 bytes, but it
shouldnt hurt anything to leave it, I left it becuase that is what you
started out doing, although for other reasons.

touch /tmp/vm.$$
for i in /var/spool/asterisk/voicemail/default/*; do
  find $i/INBOX -mmin +1 -and -size +3c -and -name \*.wav \
      -exec rm {} \;
  find $i/INBOX -mmin +1 -and -size +3c -and -name \*.WAV \
      -exec rm {} \;
  find $i/INBOX -mmin +1 -and -size +3c \
      -exec cp -f /tmp/vm.$$ {} \;
done
rm /tmp/vm.$$


This of course could still be optimized further, but to keep it simple I
decided to use what you originally did as a base...

app_voicemail can detect a gap in the sequencing between any rm and
creation of a replacement file, so I create a dummy file in /tmp then cp
that over the desired file to avoid that.  

find is not that processor friendly so you will want to watch out if you
have a large number of users/voicemails.

I also dont see that big of a point in doing this, after how many years
and hundreds of thousands of voicemails that a user has listened to do
you finally reset that number?  or do you want a life count forever?

Further the way app_voicemail works the larger that directory is the
more processing that is required to find the next available sequence
number ...


-- 
Trixter http://www.0xdecafbad.com     Bret McDanel
Belfast IE +44 28 9099 6461    DE +49 801 777 555 3402
Utrecht NL +31 306 553058      US WA +1 360 207 0479
US NY +1 516 687 5200          FreeWorldDialup: 635378
http://www.sacaug.org/ Sacramento Asterisk Users Group




More information about the asterisk-users mailing list