Marv wrote:
> Hello,
>
> I've got an issue that I can't seem to figure out.
>
> I'm trying to run some mount and rsync commands from inside a perl
> script.
>
> I've figured out from other postings that you have to use a system
> call and seperate all the command line options with quotes and commas.
> I'm not sure why this is, but I can never get the commands to work if
> I enclose them with backticks? Can anybody explain this?
>
> Anyway, if the commands could be enclosed in backticks I would have my
> problem solved, but since I have to use system (), I can't seem to
> figure out how to capture this data either to a variable or a file.
> I've tried using '2>&1 tmp.errors' but this doesn't work either
> because of the commas. Here is a sample of what I'm doing:
>
> system (
> "mount",
> "-r",
> "-t",
> "smbfs",
>
> "-o","username=$adminuser,password=$adminpass",
> "//$ip/$ashare",
> "/share/$nbname/$ashare",
> "2>&1 tmp.errors"
> );
>
> This method doesn't work because it takes the '2>&1 tmp.errors' as
> another option of mount and bombs out. If I include it at the end of
> '/share/$nbname/$ashare' then it takes as part of the name of the
> mount point and bombs out.
>
> Can anybody help me capture this info? Or show me how this can be down
> with backticks.
>
> Thanks.
> Marv
>
I have several perl scripts that run as cron jobs and I want to capture
all the output into a log file for later review. I use a two stage
approach to do this. The cron job is a shell script that runs the perl
program.
This is a snip of the perl portion. The main concept came from the Perl
Cookbook, O'Reilly, ISBN 1-56592-243-3.
------------- snippet -------------
my @archiveDir = ("/mnt/Archives", "/tmp", "/root");
foreach my $var ( @archiveDir) {
my $args = "$var/\*$cleanDate\*";
print "Removing files matching [$args]\n";
print "\tRunning [rm -f $args]\n";
open (MyCmd, "rm \-f $args |") or die "Can't run program: $!\n";
while (<MyCmd>) {
my $output .= $_;
print $output;
}
close (MyCmd);
}
-------------- end snippet ----------
The shell script which executes the perl program clean-archive is as
follows.
#!/bin/bash
#
runDate=`date +%F`
logFile=/root/clean-archive-$runDate.log
/root/clean-archive > $logFile 2>&1
While this may not be the most elegant approach I find it works well for
me. In any case, it's another varient for your consideration.
--
Les Hazelton
Registered Linux user # 272996
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird -
http://enigmail.mozdev.org
iD8DBQFAH8EvoMRiAeiXZ8MRAsPpAJ4xUM4zxQwNfdonuBX6kh PipCvRHQCfQeYX
g7mC/66tlJkRXOgLj4c98P0=
=k+6h
-----END PGP SIGNATURE-----