logos

With Andrii Grytsenko


Technical Diary - With Andrii Grytsenko

Some perl functions for monitoring

I would like to provide you library which was very useful for me during my working under monitoring system.

To make it works you have to install next perl libraries :

Net::SSH::Expect;
Net::SCP::Expect;
Net::SFTP::Foreign;
Net::FTP;

It’s easy to do through cpan. For example:

# cpan i Net::SSH::Expect

or download directly from cpan

function exec_cmd__ :

This function execute command at remote host. Example:

exec_cmd__(hostname, username, password, port, command)

function sub transfer_file__ :

This function can get or put file to remote host via ssh. Example :

transfer_file__(hostname, username, password, port, source file|directory, destination file|directory, method)

where option “method” can be “fh”(means get file from somewhere and put to localhost) or “th”(send file to host)

function sub sftp_func__ :

This function can get and send file to remote computer via sftp protocol. Example
sftp_func__(hostname, username, password, port, source file|directory, destination file|directory, method)

Where option “method” can be ‘get’(get file from remote host) and ‘put’(put file to remote host) and ‘del’(delete file from remote host )
NOTICE: if you use method “del” please specify the target as “source_file” and skip “destination_file” option

function ftp_func__ :

This function get and delete remote file via ftp protocol. Example:

ftp_func__(hostname, username, password, port, source file|directory, destination file|directory, method)
where option “method” can be ‘get’ or ‘put’

function get_file_via_ftp__:

This function is the same to previous one EXCEPT its doesn’t put a file at remote computer and when its get a file doesn’t remove it at remote system. Example:

get_file_via_ftp(hostname, username, password, port, source file|directory, destination file|directory)

function get_yesterday__:

This function return date of yesterday in format which was got by function as first argument. Example:

get_yesterday__(”YYYYDDMM”), get_yesterday__(”DDMMYYYY”) and so on.

How it’s use? Good question :)

Download this library and put into the /usr/lib/perl5/Net/. Ex.:

# cp monitoring.pm /usr/lib/perl5/Net/

Create new test script :
$ cat > test.pl
#!/usr/bin/perl
use monitoring;
$yesterday=monitoring::get_yesterday__("DDMMYYYY");
print "$yesterday\n";

Set executable rights:
$ chmod +x test.pl

And run it:
$ ./test.pl
11062009

That’s all :)

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

Translate