Sponsored Content
Full Discussion: Help with perl scripting
Top Forums Shell Programming and Scripting Help with perl scripting Post 302390127 by linuxgeek on Wednesday 27th of January 2010 02:51:31 AM
Old 01-27-2010
Help with perl scripting

Hi All,

I need to run smartctl using nagios account but I'm not familiar with perl scripting.
The existing script runs smartctl using root account. I need it to run using nagios to eliminate security risks.

Code:
#!/usr/bin/perl -w
# checks for possible disk errors
use strict;

my $smartctl=preCheck();
my $name=`hostname`;
my $remoteHost=$ARGV[0];
my $remoteDisk=$ARGV[1];
    CHECK: my $dskCheck1=`ssh -o StrictHostKeyChecking=no nagios\@$remoteHost $smartctl -i $remoteDisk`;
    my $retry=1;
        if (grep /Enabled/ig, $dskCheck1) {
            #print "smart support for $remoteDisk in $remoteHost is enabled. proceeding with check...\n";
            report(dskCheck2($remoteDisk), $remoteDisk);
        } elsif (grep /Unavailable/ig, $dskCheck1) {
            print "smart support for $remoteDisk in $remoteHost is unavailable.\n";
            exit 3;
        } else {
            ##try to enable
            unless ($retry==2) {
                #print "smart support for $remoteDisk in $remoteHost is currently disabled. trying to enable...\n";    
                $retry++;
                `ssh -o StrictHostKeyChecking=no nagios\@$remoteHost $smartctl -s on $remoteDisk`;
                goto CHECK;
            } else {
                my $err="Retry $retry: Failed enabling smart support for $remoteDisk in $remoteHost. [".scalar(localtime)."]\n
";
                logThis($err);
                print $err;
                exit 3;
            }
        }

## subs
sub preCheck {
    #check if privileged
=comment
    my $me=`whoami`;
    unless ($me eq "root\n") {
        print "You aint root!\n";
        exit 3;
    }
=cut
    #check for arguments passed
    unless (@ARGV==2) {
            print "Usage: $0 remoteHost /path/to/dev.\n";
            exit 3;
    }
    #look for smartctl in the usual places
    my $remoteHost=$ARGV[0];
    my $searchRes=`ssh -o StrictHostKeyChecking=no nagios\@$remoteHost which smartctl`;
    my @smartctls=split(/ /, $searchRes);
    foreach my $smartctl (@smartctls) {
        if ($smartctl=~/bin.+smartctl/g) {
        chomp $smartctl;
            #print "found $smartctl\n";
            return $smartctl;
        }
    }
    print "Unable to find smartctl. It\'s in the smartmontools package.\n";
    exit 3;
}

sub dskCheck2 {
    my $disk=$_[0];
    my $dskCheck2=`ssh -o StrictHostKeyChecking=no nagios\@$remoteHost $smartctl -t short $disk`;
    sleep 120;
    my $dskCheck2Res=`ssh -o StrictHostKeyChecking=no nagios\@$remoteHost $smartctl -l error $disk`;
    return $dskCheck2Res;
}

I really appreciate your reply guys on this forum. Smilie
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Perl scripting

hi Can any one suggest me book for perl scripting on UNIX Platform. Regards (2 Replies)
Discussion started by: rochitsharma
2 Replies

2. Shell Programming and Scripting

perl scripting

Hi does anyone know how to ouput "I love scripting" to "scripting love I" without using reverse() function in perl? Thanks (2 Replies)
Discussion started by: ccp
2 Replies

3. Shell Programming and Scripting

Need help in perl scripting.

Hi, To run a perl script i am giving command like this in DOS prompt d:> perl D:\<dir_name>\<dir_name>\sample.pl Its throwing the following error while running the above syntax error at <eval 4> line 1, near "use D:" Can anyone help? (3 Replies)
Discussion started by: mvictorvijayan
3 Replies

4. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

5. UNIX for Dummies Questions & Answers

Need help configuring Active Perl on Windows Vista.: Perl Scripting on Windows

Hi All, Need help configuring Active Perl on Windows Vista. I am trying to install Active Perl on Windows Vista. The version of Active Perl i am trying to install is : ActivePerl 5.10.1 Build 1006 After installing it through cmd, When i try to run perl -v to check the version, i get the... (2 Replies)
Discussion started by: Vabiosis
2 Replies

6. What is on Your Mind?

Shell scripting vs Perl scripting

Hi all, I would like to start developping some good scripting skills. Do you think it would be best to start with shell scripting or Perl? I already got a fundation, really basics, in perl. but I am wondering what would be best to be good at first. Can you please help me determine which one to... (14 Replies)
Discussion started by: Pouchie1
14 Replies

7. What is on Your Mind?

Shell Scripting vs Perl scripting

Gents, I have been working in a Solaris/Unix environment for about 9 months. I took some linux classses online before getting the job. But, I am not very good at scripting. I want to learn how to script. Do you think that I should start with Shell scripting or Perl? I wanted to continue with... (2 Replies)
Discussion started by: Pouchie1
2 Replies

8. Web Development

Perl scripting or shell scripting?

i am going to study any one of the scripting languages mentioned above(shell 0r perl scripting) . Which is having more scope for a fresher? (1 Reply)
Discussion started by: Anna Hussie
1 Replies

9. Shell Programming and Scripting

need help in PERL Scripting

I am having file xyz.log Its content is like this int main() { d; #ifdef e; f; #else g; #ifdef h. #else i; (2 Replies)
Discussion started by: naaj_ila
2 Replies

10. Shell Programming and Scripting

Perl Scripting

I have create this shell script #!/bin/sh if ; then echo "Usage: ./script <filename>" exit 1 elif ; then fname="$1" fi output="output.txt" i=0 ... (11 Replies)
Discussion started by: Evelin90
11 Replies
GSmartControl(1)						   User Commands						  GSmartControl(1)

NAME
GSmartControl - Hard disk drive health inspection tool SYNOPSIS
gsmartcontrol [OPTIONS] gsmartcontrol-root [<desktop> [OPTIONS]] DESCRIPTION
GSmartControl is a graphical user interface for smartctl (from smartmontools), which is a tool for querying and controlling SMART (Self- Monitoring, Analysis, and Reporting Technology) data on modern hard disk drives. It allows you to inspect the drive's SMART data to deter- mine its health, as well as run various tests on it. This manual page documents briefly the gsmartcontrol and gsmartcontrol-root commands. gsmartcontrol-root command launches gsmartcontrol with administrative privileges. The desktop argument specifies which desktop is currently running, for automatic selection of native su mechanism. Valid values for desktop are auto, kde, gnome, other. OPTIONS
Help Options: -?, --help Show help options --help-all Show all help options --help-gtk Show GTK+ options --help-debug Show logging options Application Options: -l, --no-locale Disable locale -V, --version Display version information --no-scan Don't scan devices on startup --no-hide-tabs Don't hide non-identity tabs when SMART is disabled. Useful for debugging. --add-virtual Load smartctl data from file, creating a virtual drive --add-device Add this device to device list. Useful with --no-scan to list certain drives only. --display=DISPLAY X display to use -v, --verbose Enable verbose logging; same as --verbosity-level 5 -q, --quiet Disable logging; same as --verbosity-level 0 -b, --verbosity-level Set verbosity level [0-5] COPYRIGHT
Copyright (C) 2008 - 2009 Alexander Shaduri <ashaduri 'at' gmail.com> AUTHOR
This manual page was originally written by Giuseppe Iuculano <giuseppe@iuculano.it>, for the Debian project. gsmartcontrol GSmartControl(1)
All times are GMT -4. The time now is 01:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy