Skip navigation

Category Archives: Scripting

Since i  have no idea how to script, going along i still try to script something.,… most of the time being unsuccessfull! 😦  My attempts are usually in either in Bash or Perl. Please do not laugh at my scripting ignorance –  i am a noob in this area!

The first script i tried out what the below:

Reading the first line of remote server’s service.

_________________________________________________________________________________________________________

#!/usr/bin/perl

# file: lgetr.pl

use IO::Socket;
# Provides an object-oriented interface for network sockets operations

my $server = shift;
# shift – host and service name are moved off the command line and placed in a variable called “server”

my $fh = IO::Socket::INET->new($server);
# Opening a network socket

my $line = <$fh>;
# <> to read a line from a text from the socket into the variable $line which will be immediately printed.

open (SAVEOUT,”>&STDOUT”);
#open file handler and copy it as STDOUT
open (STDOUT,”>results.txt”) or die “Can’t open results.txt: $!”;
#place the file handle contents into reults.txt (where create txt file if does not exist)

#the file will contain the below
print $line;
print “Client date: “;
system “date”;

#recall file handler and close it.
#print the remaining at the default (command line) prompt

open (STDOUT,”>&SAVEOUT”);
print “Done!\n”;
________________________________________________________________________________________________________

Chmod 775

./ lgetr.pl <server-address:smtp>

Result.txt will contain:

220 wenzu64.kirkland.net Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at  Wed, 16 Jul 2008 21:42:25 +0200
Client date: Wed Jul 16 21:42:25 CEST 2008

Advertisements