'cpmv' instead of 'cp' Re: [asterisk-users] [tip]semicolon trouble:
System($(sleep 4;
cp 1.call out)&) not working, but System($( sleep 4 && cp 1.call out)&)
; )
Robert Michel
news at robertmichel.de
Sat Jul 8 07:33:37 MST 2006
Salve Tzafrir, *!
On Sat, 08 Jul 2006, Tzafrir Cohen wrote:
> > Sytem($( sleep 4 && cp 1.call /var/spool/asterisk/outgoing) &)
>
> However you should not copy to the outgoing queue. You should mv a file
> there.
Right, I remember that a good friend of mine talked about the
disadvantages of the unrreleiable beheavier of cp for long time
and that he gave me the advice to do not cp with asterisk as I
started with *.
Could be, that I thougtwould need "sleep 4"
because of trouble with 'cp' ;)
So I'm wondering why there is no gnu-tool cpmv.
Where would be the best place to store a cpmv script?
My try to build one:
#!/bin/bash
# cp is not atomic and not reliable
# for fast reading process e.g. inside
# asterisk to store a copy to
# /var/spool/asterisk/outgoing
# cpmv
# copy a file to /tmp first and
# move it then to your target.
#
# This solution does not work with
# wildcards like '?' or '*'
# ../name is also not working
# s : source
# t : target
# f : file
# p : path
# $1 : source path/file
# $2 : target path/file
#
# store it e.g. /usr/bin/cpmv
# cpmv by news at robertmichel.de 2006-08-07
# for testing if a path is given
sslash=$(echo $1 | sed 's/[^/]//g')
tslash=$(echo $2 | sed 's/[^/]//g')
# extract filename from $1 $2
sf=${1##*/}
tf=${2##*/}
sp=${1%/*}
tp=${2%/*}
# echo sf $sf
# echo tf $tf
# echo sp $sp
# echo tp $tp
# exit when no sourcefile is given
if [[ $sf = "" ]]; then
# echo no given sourcefile
exit
fi
# or exit when source=target
if [[ $sp$sf = $tp$tf ]]; then
# echo source=target
exit
fi
# extract pathnames from $1 $2
# and add "/" at the end
if [[ $sslash != "" ]]; then
sp=$(echo $sp/ )
else
# in case no source pathname is given use 'pwd'
sp=$(echo $(pwd)/)
fi
if [[ $tslash != "" ]]; then
tp=$(echo $tp/ )
else
tp=$sp
fi
# echo 2sp $sp
# echo 2tp $tp
# echo 2sf $sf
# echo 2tf $tf
# now lets cp -p sourcefile to /tmp
# and move it then to targetpath
if [[ $tf != "" ]]; then
cp -p $sp$sf /tmp/$sf.cpmv.tmp; mv /tmp/$sf.cpmv.tmp $tp$tf
else
cp -p $sp$sf /tmp/$sf.cpmv.tmp; mv /tmp/$sf.cpmv.tmp $tp$sf
fi
# EOF
More information about the asterisk-users
mailing list