Problems with a PERL script.
Hello all! I have a script that has started to die on me since installing 9.3 i get rikjoh@sparhawk:~> perl bin/transfer_cam.pl No such file or directory The code is a s follows: #!/usr/bin/perl use strict; use warnings; my $dst_dir = "/mnt/network/linux/hdc/Pictures"; my $src_dir; for(1..10){ { open my $in,"/proc/mounts" or die "$!\n"; $/=undef; ($src_dir) = <$in>=~/ (\S*usb-\S*)/; close $in; } last if defined $src_dir; sleep 2; } die "Could not calculate \$src_dir" unless defined $src_dir; my @time = localtime(time); my( $year ) = $time[5]=~/(\d\d)$/; my $month = $time[4]+1; $month="0$month" if $month<10; my $day = $time[3]; $day="0$day" if $day<10; $dst_dir.="/$year/$month/$year$month$day"; my $xx="01"; while( -d "$dst_dir.$xx" ){ $xx++; } $dst_dir.=".$xx"; mkdir $dst_dir or die "$!\n"; `cp -r $src_dir/dcim/100pentx/* $dst_dir/`; Can anyone help me? Where and why is it barfing? -- /Rikard " Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without loosing something." -R. Stallman --------------------------------------------------------------- Rikard Johnels email : rikjoh@norweb.se Mob : +46 763 19 76 25 PGP : 0x461CEE56 ---------------------------------------------------------------
On 5/11/05, Rikard Johnels
Hello all! I have a script that has started to die on me since installing 9.3
i get rikjoh@sparhawk:~> perl bin/transfer_cam.pl No such file or directory
The code is a s follows:
#!/usr/bin/perl use strict; use warnings;
my $dst_dir = "/mnt/network/linux/hdc/Pictures";
my $src_dir; for(1..10){ { open my $in,"/proc/mounts" or die "$!\n"; $/=undef; ($src_dir) = <$in>=~/ (\S*usb-\S*)/; close $in; } last if defined $src_dir; sleep 2; }
die "Could not calculate \$src_dir" unless defined $src_dir; my @time = localtime(time);
my( $year ) = $time[5]=~/(\d\d)$/; my $month = $time[4]+1; $month="0$month" if $month<10; my $day = $time[3]; $day="0$day" if $day<10;
$dst_dir.="/$year/$month/$year$month$day";
my $xx="01"; while( -d "$dst_dir.$xx" ){ $xx++; } $dst_dir.=".$xx";
mkdir $dst_dir or die "$!\n"; `cp -r $src_dir/dcim/100pentx/* $dst_dir/`;
Can anyone help me? Where and why is it barfing? --
/Rikard
" Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without loosing something." -R. Stallman
--------------------------------------------------------------- Rikard Johnels email : rikjoh@norweb.se Mob : +46 763 19 76 25 PGP : 0x461CEE56 ---------------------------------------------------------------
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Hi, it looks like, as it appears to me in a very short test, that you are trying to create a directory containing the current date as a subfolder structure.. i mean this line where you append the date to $dst_dir:
$dst_dir.="/$year/$month/$year$month$day";
and a counting number.. ( on a new day it will be allways "01" because the "-d" returns false.. )
$dst_dir.=".$xx";
and this line where you try to create it:
mkdir $dst_dir or die "$!\n";
Given this, the whole substructure is build up dynamicly, in other words it changes every day at least 2 subfolders ( $day and $xx ). You're trying to create it recursively which should not work with the perl mkdir command.. And it fails on my 9.2 box at home as i expected. If i did understand you right you'd wanted to create the whole path ( until $xx ) at once if does not exist. You could give mkpath from the file::Path module a try.. Markus
On Wednesday 11 May 2005 23.32, Markus Natter wrote:
On 5/11/05, Rikard Johnels
wrote: Hello all! I have a script that has started to die on me since installing 9.3
i get rikjoh@sparhawk:~> perl bin/transfer_cam.pl No such file or directory
The code is a s follows:
#!/usr/bin/perl use strict; use warnings;
my $dst_dir = "/mnt/network/linux/hdc/Pictures";
my $src_dir; for(1..10){ { open my $in,"/proc/mounts" or die "$!\n"; $/=undef; ($src_dir) = <$in>=~/ (\S*usb-\S*)/; close $in; } last if defined $src_dir; sleep 2; }
die "Could not calculate \$src_dir" unless defined $src_dir; my @time = localtime(time);
my( $year ) = $time[5]=~/(\d\d)$/; my $month = $time[4]+1; $month="0$month" if $month<10; my $day = $time[3]; $day="0$day" if $day<10;
$dst_dir.="/$year/$month/$year$month$day";
my $xx="01"; while( -d "$dst_dir.$xx" ){ $xx++; } $dst_dir.=".$xx";
mkdir $dst_dir or die "$!\n"; `cp -r $src_dir/dcim/100pentx/* $dst_dir/`;
Can anyone help me? Where and why is it barfing? --
/Rikard
" Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without loosing something." -R. Stallman
--------------------------------------------------------------- Rikard Johnels email : rikjoh@norweb.se Mob : +46 763 19 76 25 PGP : 0x461CEE56 ---------------------------------------------------------------
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Hi,
it looks like, as it appears to me in a very short test, that you are trying to create a directory containing the current date as a subfolder structure..
i mean this line where you append the date to $dst_dir:
$dst_dir.="/$year/$month/$year$month$day";
and a counting number.. ( on a new day it will be allways "01" because the "-d" returns false.. )
$dst_dir.=".$xx";
and this line where you try to create it:
mkdir $dst_dir or die "$!\n";
Given this, the whole substructure is build up dynamicly, in other words it changes every day at least 2 subfolders ( $day and $xx ). You're trying to create it recursively which should not work with the perl mkdir command..
And it fails on my 9.2 box at home as i expected. If i did understand you right you'd wanted to create the whole path ( until $xx ) at once if does not exist. You could give mkpath from the file::Path module a try..
Markus
How do i invole that command? /me is just not a programer... :( -- /Rikard " Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without loosing something." -R. Stallman --------------------------------------------------------------- Rikard Johnels email : rikjoh@norweb.se Mob : +46 763 19 76 25 PGP : 0x461CEE56 ---------------------------------------------------------------
On 5/12/05, Rikard Johnels
On Wednesday 11 May 2005 23.32, Markus Natter wrote:
On 5/11/05, Rikard Johnels
wrote: Hello all! I have a script that has started to die on me since installing 9.3
i get rikjoh@sparhawk:~> perl bin/transfer_cam.pl No such file or directory
The code is a s follows:
#!/usr/bin/perl use strict; use warnings;
my $dst_dir = "/mnt/network/linux/hdc/Pictures";
my $src_dir; for(1..10){ { open my $in,"/proc/mounts" or die "$!\n"; $/=undef; ($src_dir) = <$in>=~/ (\S*usb-\S*)/; close $in; } last if defined $src_dir; sleep 2; }
die "Could not calculate \$src_dir" unless defined $src_dir; my @time = localtime(time);
my( $year ) = $time[5]=~/(\d\d)$/; my $month = $time[4]+1; $month="0$month" if $month<10; my $day = $time[3]; $day="0$day" if $day<10;
$dst_dir.="/$year/$month/$year$month$day";
my $xx="01"; while( -d "$dst_dir.$xx" ){ $xx++; } $dst_dir.=".$xx";
mkdir $dst_dir or die "$!\n"; `cp -r $src_dir/dcim/100pentx/* $dst_dir/`;
Can anyone help me? Where and why is it barfing? --
/Rikard
" Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without loosing something." -R. Stallman
--------------------------------------------------------------- Rikard Johnels email : rikjoh@norweb.se Mob : +46 763 19 76 25 PGP : 0x461CEE56 ---------------------------------------------------------------
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
Hi,
it looks like, as it appears to me in a very short test, that you are trying to create a directory containing the current date as a subfolder structure..
i mean this line where you append the date to $dst_dir:
$dst_dir.="/$year/$month/$year$month$day";
and a counting number.. ( on a new day it will be allways "01" because the "-d" returns false.. )
$dst_dir.=".$xx";
and this line where you try to create it:
mkdir $dst_dir or die "$!\n";
Given this, the whole substructure is build up dynamicly, in other words it changes every day at least 2 subfolders ( $day and $xx ). You're trying to create it recursively which should not work with the perl mkdir command..
And it fails on my 9.2 box at home as i expected. If i did understand you right you'd wanted to create the whole path ( until $xx ) at once if does not exist. You could give mkpath from the file::Path module a try..
Markus
How do i invole that command? /me is just not a programer... :( --
/Rikard
" Sharing knowledge is the most fundamental act of friendship. Because it is a way you can give something without loosing something." -R. Stallman
--------------------------------------------------------------- Rikard Johnels email : rikjoh@norweb.se Mob : +46 763 19 76 25 PGP : 0x461CEE56 ---------------------------------------------------------------
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
The common File:: Modules should be already installed on a suse box, so just try the most simple first: replace the line: mkdir $dst_dir or die "$!\n"; with: use File::Path; mkpath($dst_dir); ( if it fails it will croak anyway ) if you want to catch exceptions you can do this with eval: eval { mkpath($dst_dir) }; if ($@) { print "Couldn't create $dir: $@"; } mkpath has some more options to be set, if you need, visit a documentation site, e.g.: http://perl.active-venture.com/lib/File/Path.html hope this helps.. Markus
participants (2)
-
Markus Natter
-
Rikard Johnels