Operating System - HP-UX
1753730 Members
4683 Online
108799 Solutions
New Discussion юеВ

Re: script to cp a DIR to DISK runing it using cron job

 
SOLVED
Go to solution
noe
Occasional Advisor

script to cp a DIR to DISK runing it using cron job

can someone help me create a script that will copy dir1, dir2, dir3 on disk1 to a dir on disk2;need to log any errors also i need to run it daily using cron
5 REPLIES 5
James R. Ferguson
Acclaimed Contributor

Re: script to cp a DIR to DISK runing it using cron job

Hi:

This could be as simple as a crontab entry like:

0 17 * * cp -Rp /disk1/dir1 /disk1/dir2 /disk1/dir3 /disk2 && echo OK || echo FAILED

Regards!

...JRF...
Mel Burslan
Honored Contributor
Solution

Re: script to cp a DIR to DISK runing it using cron job

The definition of disk on HPUX is a little bit fuzzy as the use of LVM is default behavior and one LVM volume can be spread over several physical disks.

Having said that, let's assume your "disk" is mounted on /new_disk filesystem and you want to copy the contetns of /data/dir1, /data/dir2 and /data/dir3 onto this /new_disk filesystem

you just create a script, let's say, /var/adm/datacopier.sh as follows:

#!/usr/bin/ksh
timestamp=`date | awk {'print $2 $3 $6'}`
for dir in /data/dir1 /data/dir2 /data/dir3
do
cp -rp ${dir} /new_disk/somedir/${dir}.${timestamp}
done

save and exit. Make sure it is executable by the person/group according to its file permissions.

then edit your crontab via command crontab -e and append this line

0 3 * * * /var/adm/datacopier.sh > /var/adm/datacopier.log 2>&1

Now, everyday at 3 AM, your directories will be copied to the destination disk and they will have a timestamp on them, in case you want to copy more than one day's worth.

Hope this helps
________________________________
UNIX because I majored in cryptology...
noe
Occasional Advisor

Re: script to cp a DIR to DISK runing it using cron job

thank you . now, will this overwrite the data daily?
James R. Ferguson
Acclaimed Contributor

Re: script to cp a DIR to DISK runing it using cron job

Hi:

> thank you . now, will this overwrite the data daily?

In the simple script I suggested, yes. In Mel's method, no, since he appends a date (e.g. May132009) to each destination directory name.

Regards!

...JRF...
noe
Occasional Advisor

Re: script to cp a DIR to DISK runing it using cron job

thank you all i will try your suggestions