Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automated copy of files from one directory to another

Status
Not open for further replies.

spsilver

Technical User
Dec 10, 2001
5
US
Hi! Please pardon my simplistic question. I am a newby to Linux/Perl.

I am wondering the best way to accomplish the copy of files named mall.* from
/home/public_html/files/
to
/home/public_html/john

I need all the mall.* files copied daily at 10:00 am. There are about 9 files total.
mall.1 , mall.2 , mall.3, etc...

Someone have a script or other suggestion.. THANKS!
 
As with every problem, there are many ways to solve it in Perl.

Probably the easiest would be to use the "system" command to copy the all the files in dir1 to dir2, like

#!/path/to/perl -w

my $from = "/home/public_html/files/*";
my $to = "/home/public_html/john";

my @args = ("cp", "-R", "$from_dir", "$to_dir);
system(@args) == 0
or die "system @args failed: $?";

--------------------------------------------------
Careful - this is completely untested, but hopefully it
isn't far from working. You'll probably have to play with
it some, but it's a start.

Read up on the "system" command by doing

perldoc -f system

at the command prompt.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Thank you! I will read the docs you suggest.
2 questions (before reading)

1. Would this be named as a .cgi and ran as such or what would trigger it to run daily at a certain time?

2. I do not want to copy all the files from dir1 to dir2. Only files that are mall.*
What change would need to be made? Is it like a dos wildcard? Ie; mall.* would work?
 
Also read up on "cron" by doing

man cron
man crontab

"cron" is the facility on Unix and Linux to allow you to run commands/scripts/jobs at regular intervals, like every day at 10:00. You can also search the web(I use for something like "cron linux", and you might want to put the specific distribution you are working on - also try searching the distributions site - I used Redhat 7.2, so I would go to and search for "cron".

This does NOT need to be a cgi script - just create your script so you can run it at the command line, and then look into putting that script into cron to have it run every day at 10:00.

And for "mall.*", you would chang the code to

my $from = "/home/public_html/files/mall\.*";

and again, you'll probably need to play around with it to get it to work right.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
Thank you for the advice ( and fast response ).

Let me "play" for a bit and see what happens.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top