Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copying files

Status
Not open for further replies.

segment

ISP
Jun 15, 2004
225
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top