Operating System - HP-UX
1843948 Members
2168 Online
110226 Solutions
New Discussion

List File/s created yesterday and copy files to another directory

 
SOLVED
Go to solution
Pando
Regular Advisor

List File/s created yesterday and copy files to another directory

I have a script the will list the file yesterday
and have it copied to another directory. But there was an error during the copy stage. Herewith is the script:
....
....
....
dta="/Informix"

export YESTERDAY=$(TZ=$(date +%Z)+24; date '+%b %e')

for i in `ls -l $dta/*PR*.res | grep -F "${YESTERDAY}"`
do
# /usr/bin/cp -p $i /test/temp
# echo "$i copied"
echo $i
done
...

The result was:

-rwxrwxrwx
1
root
sys
37533
Nov
10
07:17
/Informix/RZ1214B35YI_0443A_PR0119A_2004119_195123.res

I only needed the file RZ1214B35YI_0443A_PR0119A_2004119_195123.res
to be copied.

Maximum points for all correct replies.

Many thanks!


3 REPLIES 3
Sridhar Bhaskarla
Honored Contributor
Solution

Re: List File/s created yesterday and copy files to another directory

Hi,

Replace 'for i' statement with

ls -l $dta/*PR*.res | grep -F "${YESTERDAY}" |awk '{print $9}' |while read FILE
do
#/usr/bin/cp -p "$FILE" /test/temp
echo $i
done

I didn't use 'for' because if any of filenames have spaces in them. But your script needs some more work anyway.

-Sri


You may be disappointed if you fail, but you are doomed if you don't try
Sridhar Bhaskarla
Honored Contributor

Re: List File/s created yesterday and copy files to another directory

hmmm..correction time. 'echo $FILE' not 'echo $i' in my response.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Pando
Regular Advisor

Re: List File/s created yesterday and copy files to another directory

Thanks Sri!

I've taken care of that!
It works!