I learned perl and did not use for a long time. Now i have a problem, i hope you can show me to edit the code and make it work. I have a iplist.txt , when a system boot up, it will write IP , hotsname to iplist.txt
10.31.61.230,fall11,Thu 03/30/2011 15:20:46.70 10.31.61.212,spring96,Thu 03/30/2011 15:19:56.89 10.31.61.230,spring96,Thu 03/31/2011 15:40:46.70 10.31.61.230,winter11,Thu 03/31/2011 15:40:46.70 Because IP will change and hostname can be change too because it has d +ifferent windows OS How do i get new log with the latest info ? like latestip.txt Now 10.31.61.230,fall11,Thu 03/30/2011 15:20:46.70 change hostname the next day so i have to keep new hostname and ip add +ress 10.31.61.230,winter11,Thu 03/31/2011 15:40:46.70 If we have IP change from 10.31.61.212,spring96,Thu 03/30/2011 15:19:56.89 to 10.31.61.230,spring96,Thu 03/31/2011 15:40:46.70 then keep the new IP address and hostname 10.31.61.230,spring96,Thu 03/31/2011 15:40:46.70 so it will create new file and this new log latestip.txt will be 10.31.61.230,winter11,Thu 03/31/2011 15:40:46.70 10.31.61.230,spring96,Thu 03/31/2011 15:40:46.70
#viewip.pl #print "content-type: text/html\n\n"; use Time::Local; $today = timelocal(localtime); $datafile=`cat ../hosts/iplist.txt | sort -r | sort -u -t ',' -k 2,2 > + ../hosts/latestip.txt`; my $count = 0; open (DATA,"/home/myplace/hosts/latestip.txt") || die ("Can't Open dat +a File \n"); @data=<DATA>; close DATA; &header_response; $x=0; foreach $line (@data) { $x++; ($ip, $hostname , $datetime)=split(/\,/,$line); print "<TD BGCOLOR='d3d3d3'>$hostname</TD><TD BGCOLOR='d3d3d3'>$ip +&nbsp;</TD><TD BGCOLOR='d3d3d3'>$datetime&nbsp;</TD></TR> \n"; $count++; } &footer_response; ###################################################################### +############################## sub header_response { print "Content-type: text/html\n\n"; print "<HTML><HEAD><TITLE>test</TITLE>\n"; print "</HEAD>\n"; print qq^<BODY background="images/bg2.jpg" TEXT="blue" LINK="blue" + VLINK="#9900CC" ALINK="#330066">\n^; print "<CENTER><h1><font color=black>Our IP Info</font></h1></CENT +ER>\n"; print "<BR>\n"; print "</form></CENTER>\n"; print "<center><FONT size=+1><TABLE BORDER=1><TR bgcolor=#669900>< +TD><center><font color=white>Host Name</center></TD><TD><center><font + color=white>IP address</center></TD><TD><font color=white><center>La +st Boot Windows</center></TD></TR>\n\n"; return; } sub footer_response { print "</TABLE></font></CENTER>\n"; print "<BR><BR><BR><BR>\n"; print " </BODY></HTML>\n"; return; }
Thanks for teaching me.

In reply to How to get latest IP and hostname. by britney

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.