The following is a Perl script that can be used to connect to and list an FTP directory.
This can be extended to accept the paremeters as required - host ip,user password, directory etc.
This also can be run in a loop or from cron to monitor connectivity or to monitor file movements(that is a not so good use!!)
use Net::FTP;
$host = '1x2.1xx.xx.xxx';
$user = 'User';
$pass = 'xxxxxxxxxxx';
$home = '/home/release;
print "Connecting...";
#connect
$ftp = Net::FTP->new($host);
#login
$ftp->login($user,$pass);
print "LoggedIn...";
#slurp
@result = $ftp->ls($home);
print "\nResult...";
for(@result)
{ print "\n";
print $_; }
$ftp->quit;
print "\n...Closed";
This is intended to be a notepad on which I scribe the technologies and experience - that I come across daily. Something that I can refer later. And if it helps anyone on the internet, I would be really happy. Post your comments and suggestions. Also anything you would like to know about. Will try my best to post it. Anything goes - Architecture, design, Java, J2EE, Groovy, Grails, Linux, Solaris, Weblogic, IBM MQ, Networking, Security, Compliance(PCI, SAS-70)
Friday, November 14, 2008
Finding lines of text following a text match - awk
Suppose you need to display x lines following a search condition.
For example, display the first 5 lines of trace following an Exception in Tomcat log.
If you are using Solaris/ Linux/ *nix, one way of doing it is to "awk" it.
Get the first five lines after a Keyword named "Exception". Feel free to change the keyword as required.
BEGIN {flag = 0}
/Exception/
{print;
flag = 5;
next}
flag >= 1 {print;
flag--;
next}
Use awk or nawk(if you have a long line - awk has a limitation on line length)
Run it as follows:
nawk -f checkex.awk *
Redirect to a file as follows
nawk -f checkex.awk * > output.txt
For example, display the first 5 lines of trace following an Exception in Tomcat log.
If you are using Solaris/ Linux/ *nix, one way of doing it is to "awk" it.
Get the first five lines after a Keyword named "Exception". Feel free to change the keyword as required.
BEGIN {flag = 0}
/Exception/
{print;
flag = 5;
next}
flag >= 1 {print;
flag--;
next}
Use awk or nawk(if you have a long line - awk has a limitation on line length)
Run it as follows:
nawk -f checkex.awk *
Redirect to a file as follows
nawk -f checkex.awk * > output.txt
Subscribe to:
Posts (Atom)