Forum Moderators: coopster & phranque

Message Too Old, No Replies

Getting cp to work

I am SO lame....

         

carfac

4:13 am on May 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, I am banging my head against the wall here- this should be the most simple script in the world to make work... and I cannot! What the heck and I missing?

Basically, all I want to do is copy files in a backup rotation. Here is the script:

cp /hd2/backups/cartoon5.tar /hd2/backups/cartoon6.tar
sleep 30
cp /hd2/backups/cartoon4.tar /hd2/backups/cartoon5.tar
sleep 30
cp /hd2/backups/cartoon3.tar /hd2/backups/cartoon4.tar
sleep 30
cp /hd2/backups/cartoon2.tar /hd2/backups/cartoon3.tar
sleep 30
cp /hd2/backups/cartoon1.tar /hd2/backups/cartoon2.tar
sleep 30
cp /hd2/backups/cartoon.tar /hd2/backups/cartoon1.tar
sleep 60

I get a copy, but an invisible one... when I ls -l, I see files like this:

cartoon6.tar?
cartoon5.tar?
cartoon4.tar?
cartoon3.tar?
cartoon2.tar?

What the heck am I doing wrong here? It CAN'T be that hard!

Oh- I am running this from CRON- does that make a difference?

Dave

phranque

10:33 am on May 22, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



is there a reason you aren't using mv instead of copy?
it should be much more efficient.
the last one should still be a cp of course...

carfac

1:11 pm on May 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No- no reason. I will try that (except fopr the last one!)

Thanks!

Dave

carfac

1:27 pm on May 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, tried it.... it still just makes copies with the "?" at the end, not regular copies. Do I need a ";" at the end of each line or something like that?

Dave

chorny

5:35 pm on May 22, 2008 (gmt 0)

10+ Year Member



In Perl:

#!/usr/bin/perl
use strict;use warnings;use diagnostics;
my $path='/hd2/backups';
foreach my $i (5..0) {
rename("$path/cartoon".$i.".tar","$path/cartoon".($i+1).".tar");
sleep(30);
}

and name your first file cartoon0.tar
You don't need cron if you do sleep(30), just make it run forever.

carfac

1:59 am on May 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Chorny:

Thanks!

Dave

phranque

6:36 am on May 23, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You don't need cron if you do sleep(30), just make it run forever.

just assuming the cron job is scheduled daily here...

- if you run this script constantly you won't really have 6 generations of daily backups unless you sleep for 24 hours.
- you won't be consuming a process 24/7 if you use cron.
- if the process fails, you won't have cron to restart it on schedule.