TheFluffyOne has asked for the wisdom of the Perl Monks concerning the following question:

I've been so overwhelmed by the excellent responses I've received to my previous queries that I'd like to request some assistance with another problem I've been avoiding for ages.

Many of my scripts run on Win32 (since this is the platform I support at work), however I've managed to hide a Linux box in a dark corner and would like to run some of the scripts on it.

The main obstacle is that in the scripts I can use lines such as:

open INFILE, "< //server/share/logfile.txt" or die "Ouch";

The only way I can see to access these logs under Linux (without installing FTP servers all over the place) is to mount the share, access the file, then unmount the share.

This seems very messy to me, and definitely isn't good if I'm reading logs from a large number of workstations.

Is there a better way to do it?

Thanks,

Gordon.

Replies are listed 'Best First'.
Re: Accessing SMB Shares from Linux
by Roger (Parson) on Nov 25, 2003 at 23:39 UTC
    You do not have to explicitly mount the share and unmount the share. You can get through via smbclient. There is an interesting module on CPAN called Filesys::SmbClient. I have copied and modified its sample script slightly -
    use POSIX; use Filesys::SmbClient; my $smb = new Filesys::SmbClient(username => "alian", password => "speed", workgroup => "alian", debug => 10); # Read a file my $server="jupiter"; my $path="doc/general.css"; my $fd = $smb->open("smb://$server/$path", '0666'); while (defined(my $l= $smb->read($fd,50))) { print $l; } $smb->close(fd);
    And of course you can access the file with a tied file handle for convenience as well.

      Thanks Roger, and also to idsfa, for the replies.

      I'll take a look at both methods to see which works best for me.

      Is there a way to do this that is portable between Win32 and Linux, or am I going to need to write a wrapper to choose between Win32/Linux code?

          Is there a way to do this that is portable between Win32 and Linux

        Yes of course. You can check the $^O variable to see whether you are on Windows or Linux platform, and act accordingly.
        use strict; if ($^O ne 'MSWin32') { # NOT on windows? require POSIX; require Filesys::SmbClient; } ... sub OpenFile { my ($server, $path, $username .... ) = @_; if ($^O eq 'MSWin32') { # open file directly as //server/path on Windows ... } else { # open file via smbclient on *nix ... } }
Re: Accessing SMB Shares from Linux
by markov (Scribe) on Nov 26, 2003 at 11:11 UTC

    A different approach to your basic need is something I used for managing more than 100 UNIX systems (many kinds of OS) in a large computing facility: send the log per email.

    Create a cron job (Linux: /etc/cron.daily/sendlog) which extract the interesting information from all log files, and then e-mail that to you. The extraction filters need some adaption to your specific needs, to reduce the number of lines. The only thing you have to do is browse through the mails, first thing every morning.

    In larger UNIX/Linux environments, you can also decide to configure syslog to send reports directly to syslog daemons on other systems (nick one of your systems as 'loghost'). This way, you can collect data from multiple systems in one file, which is easier to maintain.

Re: Accessing SMB Shares from Linux
by idsfa (Vicar) on Nov 26, 2003 at 05:52 UTC

    While not necessarily better, I feel compelled to point out smbsh and autofs as ways to hide the nasty mount/umount stuff.


    My parents just came back from a planet where the dominant life form had no
    bilateral symmetry, and all I got was this stupid F-Shirt.