Hello all. I have a script that is run from Asterisk when a call comes in. What it does (or supposed to do) is, it copies a voicemail from one directory into a few others. Is there a shorter more practical way to do this... On a one liner it would be:
for i in `ls $VoiceDir` ; do cp $i /path/to/jangroup/76xx/msg* ; done
Where I would have to enter the same line for 7 extensions (7605-7611)
Any thoughts?
#!/bin/bash
VoiceDir="/var/spool/asterisk/voicemail/jangroup/7604/INBOX"
Files=(`ls -t "$VoiceDir"`)
FileToCopy=${Files[0]:0:7}
for CurrVoicemail in 05 06 07 08 09 10 11
do
VmailComponents=(`ls -t /var/spool/asterisk/voicemail/jangroup/76"$CurrVoicemail"/INBOX/`)
Num=${VmailComponents[0]:3:4}
if [ "${VmailComponents[0]:0:3}" != 'msg' ]
then
Num="0"
else
Num=$(($Num + 1))
fi
if [ $Num -lt 10 ] ;
then
NumA="000$Num"
fi
if [ $Num -gt 99 ] ;
then
NumA="00$Num"
fi
if [ $Num -gt 999 ] ;
then
NumA="0$Num"
fi
echo $NumA
cp /var/spool/asterisk/voicemail/jangroup/7604/INBOX/$FileToCopy.wav /var/spool/asterisk/voicemail/jangroup/76$CurrVoicemail/INBOX/msg$NumA.wav
cp /var/spool/asterisk/voicemail/jangroup/7604/INBOX/$FileToCopy.txt /var/spool/asterisk/voicemail/jangroup/76$CurrVoicemail/INBOX/msg$NumA.txt
for i in `ls $VoiceDir` ; do cp $i /path/to/jangroup/76xx/msg* ; done
Where I would have to enter the same line for 7 extensions (7605-7611)
Any thoughts?
#!/bin/bash
VoiceDir="/var/spool/asterisk/voicemail/jangroup/7604/INBOX"
Files=(`ls -t "$VoiceDir"`)
FileToCopy=${Files[0]:0:7}
for CurrVoicemail in 05 06 07 08 09 10 11
do
VmailComponents=(`ls -t /var/spool/asterisk/voicemail/jangroup/76"$CurrVoicemail"/INBOX/`)
Num=${VmailComponents[0]:3:4}
if [ "${VmailComponents[0]:0:3}" != 'msg' ]
then
Num="0"
else
Num=$(($Num + 1))
fi
if [ $Num -lt 10 ] ;
then
NumA="000$Num"
fi
if [ $Num -gt 99 ] ;
then
NumA="00$Num"
fi
if [ $Num -gt 999 ] ;
then
NumA="0$Num"
fi
echo $NumA
cp /var/spool/asterisk/voicemail/jangroup/7604/INBOX/$FileToCopy.wav /var/spool/asterisk/voicemail/jangroup/76$CurrVoicemail/INBOX/msg$NumA.wav
cp /var/spool/asterisk/voicemail/jangroup/7604/INBOX/$FileToCopy.txt /var/spool/asterisk/voicemail/jangroup/76$CurrVoicemail/INBOX/msg$NumA.txt