Thanks, for the quick response my user would like to a certain list of files and there isn't a basic pattern or extention.
7Souls
Main Topics
Browse All TopicsHi, I don't do much in the way of unix scripting what I need is a Unix script to copy a list of files from one directory to another and write to a log.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi omarfarid, see the snipet of code that I sent with this questions he has all 5000 plus statements ready with a 'cp' file to destination directory. I know I can tar by extentions but that won't work because he only wants the files in his list.
example
cp /psfscm/data/BJOHNSON2009-
and this happen 5000 + times coping different files.
Thanks,
7Souls
I did.
Create a file, (using vi or cat, or notepad on a Windows machine and then ftp the file to the unix box), containing the lines from my previous post, starting with "echo start of log" and ending with "done<your file".
Change the permissions on the script file using "chmod" to make it executable.
The script does the following:
echo start of log --- prints "start of log" on the output device
echo target directory is $1 --- prints "target directory is 'the command line parameter you enter when you execute the script"
while read cp file --- reads the file that has been created for you, and discards the "cp" at the beginning of each line
do --- starts a loop
cp $file $1 --- copies the file in the list to the target directory
echo $file copied to $1 --- prints "listed_file copied to target_directory"
done < file_list --- closes loop and assigns the file named file_list as input to script.
run the script with the target_directory as the first command line option.
Thanks already_used, your idea sounds good but before I start and writing it your way. I first tried this
ex:
#!/usr/bin/ksh -xv
set -a allexport
export LOG_FILE=/psfscm/data/copy
cp /psfscm/data/BJOHNSON2009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/PORTED002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/PORTED002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/PORTED002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/PORTED002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/PORTED002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/PORTED002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/GRUBBW002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/WILLIL002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/WILLIL002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/WILLIL002009-
/psfscm/data/adhoc >> ${LOG_FILE}
cp /psfscm/data/WILLIL002009-
/psfscm/data/adhoc >> ${LOG_FILE}
Wait
This is doing the copies but its not writing to the log file:
$ ls -lrt *.log
-rw-rw-r-- 1 ps8admfn psadm 0 Aug 14 16:11 copyfile_attachments_adhoc
What am I doing wrong?
Thanks,
7Souls
How about cpio?
You could create a file called /pathname/files.txt file look like:
BJOHNSON2009-02-02-11.50.3
PORTED002009-02-02-12.45.4
PORTED002009-02-02-12.46.4
PORTED002009-02-02-12.52.2
PORTED002009-02-02-12.53.0
Then do the 2 step:
cd /psfscm/data
cat /pathname/files.txt | cpio -pv ./adhoc > /tmp/filecopy.log 2>&1
The copy output and any errors would be in /tmp/filecopy.log
This may make it easier to maintain the list of files as well.
I'm not sure how the list of files is determined, but if it's based on changes to the files and/or new files, you could do:
cd /psfscm/data
find . -mtime -1 | cpio -pv ./adhoc > /tmp/filecopy.log 2>&1
That would get anything modified or created in the last day. You could limit the filenames with a -name switch to find as well. More info would be needed to go down that road though.
You could also create a file with the commands in it called something like /usr/bin/filecopy.sh and put those commands in it, make it executable with chmod and then add it to the crontab file to automate the process.
The best way to handle this is to have all the file names to be copied in a separate file then use the following shell script to do the copying/logging. This makes it easier if you ever need to change paths.
The list of files should contain just the filename and not the path, eg:
BJOHNSON2009-02-02-11.50.3
PORTED002009-02-02-12.45.4
Business Accounts
Answer for Membership
by: omarfaridPosted on 2009-08-12 at 07:14:08ID: 25078917
you may do this with
cd /path/to/dir1
tar cf - ./*.pdf | ( cd /path/to/dir2 ; tar xvf - >> /path/to/logfile )