Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
i want to know is there a way to create a variable where I have a multile list of files called :
audit.12
audit.13
audit.14
I need to copy these files to another directory but keeping them with a date extension
I tried this ,but no luck:
#!/bin/ksh
DATE=`date +%d%m%y`
CONO=`grep [0-1][0-9]`
cp audit.$CONO /home/singgm/bckaudit
cd bckaudit
cp audit.$CONO audit.$CONO.$DATE
Thanks in advance
Hamim

A way. No error checking:
#!/bin/kshadir="/home/singgm/bckaudit"
DATE=$(date +%d%m%y)
ls -1 audit.*|while read file
do
cp $file $adir
cp $file $adir/$file.$DATE
done

Hi Nails
I tried your option ,but it gives me erors
:UX:cp: ERROR: Incorrect usage
UX:cp: TO FIX: Usage: cp [-i] [-p] f1 f2
cp [-i] [-p] f1 ... fn d1
cp [-i] [-p] [-r] d1 d2

That's a very straight forward script. It works on my Solaris 8 box. I'm not an HP-UX guy
The only problem I could see is if you spaces in your files or directories. Try places quotes around your variables:
cp "$file" "$dir"

Hi nails
ok Thanks
I did however come up with this solution as well:dir="/home/singgm/bckaudit"
DATE=`date +%d%m%y`
for FILE in $1 `ls audit.*`
do
chmod 444 $FILE
cp $FILE $dir/$FILE.$DATE
done

If it works for you fine, but let me point out a potential problem the way you use the for loop:
Your script works because you have only 1 server name per line with no white space. Let's change the algorithm. Suppose you had to read a text file a line at a time which might contain whitespace:
for line in `cat myfile`
do
echo "$line"
donesuppose myfile contains this for data:
col11 col22
col14 col24If you wanted to echo just two lines, the script fails.
Here's what you want to do
while read line
do
echo "$line"
done < myfileIn conclusion, you are using what's commonly called a Useless Use of Cat, UUOC. For more info, take a look at this link:
http://laku19.adsl.netsonic.fi/%7Eera/unix/award.html
I'm not being mean - just sharing information.

guys,
how about this.just see the below solution. let me know if it goes fine.
#!/bin/ksh
dir="/home/signgm/bckaudit"
datestamp=`date +%d%m%y`
ls -l audit.*|while read file
do
file=`echo $file|tr -s " " ";"|cut -d ";" -f9`
cp $file $dir
cp $file $dir/$file.$datestamp
donethanks
Arun S
this unix location and u have placed windows request. please specify on which platform u want solution.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |