develooper Front page | perl.beginners | Postings from December 2002

FW: Help with my script please.

Thread Next
Paul Kraus
December 4, 2002 11:04
FW: Help with my script please.
Message ID:
I just finished the learning Perl book and thought I would try and
rewrite a bash script that I had written long ago. The purpose of the
app is to mount a samba folder on a winx machine. Copy its contents to a
local folder as a mirror. I just wanted some input on my app and some
things explained if you could.

First off I am using the system "cp" so that I can preserve dates and
permissions as well as dig into subdirectories. I was going to use
File::Copy but it just seem to cumbersome to accomplish the same text.
Am I incorrect is there a "better way to do this."

Secondly I am reading the parameters from a comma delimitated file but
this is going to be changed to a real config file that is setup like
[machine name] Password=; Username=; ...

So just ignore this top portion unless you have some insights or advice.

Thirdly for some reason 80% of the time when I call system "umount ...."
the umount process hangs forever. I can't even kill it with -9.
Sometimes it comes back sometimes it doesn't. Any thoughts?

Last but easiest: 
I know I can condense these into one assignment but I can't figure it
out for the life of me. $path=$5; $path=~s/ /\\ /g;

Thanks in advance,
Paul Kraus

chomp ($dt=`date +%r`);
open CONFIG,"<backup.cfg" or die "Can't find configuration file!\n";
open LOG,">>backup.log"; &errors("New"); foreach (<CONFIG>){
    if (/^([^#].*),(.*),(.*),(.*),(.*),(.*)$/){
	    $path=~s/ /\\ /g;
	    $backupdir = "/backup/$machine";
	    mkdir $backupdir unless (-e "/backup/$machine");
	    next if ($error==1);
	    system "umount /mnt/backup";

sub backupdir{
    $test=`cp --preserve --recursive --update /mnt/backup/$path/ $_[0]
    &errors("cp",$1) if ($test=~/\/(.*)'+/);

sub mountdir{
    &errors("mount") if (system "mount","-t","smbfs","-o",
sub errors{
    $workstation= $1 if ($machine=~/\/\/(.*)/);
    select LOG;
    print "($dt) Machine off : $workstation\n" if ($_[0] eq "mount");
    if ($_[0] eq "cp"){
	print "$_[1]";
	my @path=split /\//,$_[1];
	print "$_\n" foreach (@path);
	my $filename = pop(@path);
	print "($dt) File in use :$workstation :$filename\n" if ($_[0]
eq "cp");
    if ($_[0] eq "New"){
	print "\nBackup log for ";
	print `date +%D`;
	print "------------------------\n"}
    select STDOUT;

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About