Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Servers Uptime....

Status
Not open for further replies.

leo2180

IS-IT--Management
Jun 7, 2000
52
US
Can someone tell me a function in Perl that I could use, or tell me how to get a hosts uptime and possibly get the amount of users logged on to it, or anything of that nature.  Please help I need to get this information from a server but dont know how to go about doing it...
 
Simply enclose the system calls in backticks and catch the return value in a var.<br><FONT FACE=monospace><br>#!/usr/local/bin/perl<br>$uptime = `uptime`;<br>$who = `who`;<br>print &quot;Server uptime : $uptime\n&quot;;<br>print &quot;Current users : $who\n&quot;;<br></font><br>'Hope this helps. <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
ahhh, I dont realy get what you're saying...&nbsp;&nbsp;Would the code above do exactly what I want to do?&nbsp;&nbsp;I doubt it.&nbsp;&nbsp;Dont I have to tell it which computer I want to access and what have you....<br><br>
 
Oh! you mean remote hosts!&nbsp;&nbsp;I don't know.....sounds like a good time to go surf the CPAN module list.<br><br>I know you can open pipes to telnet to other machines and pass commands and info back and forth.&nbsp;&nbsp;But, there must be an out of the can approach out there.&nbsp;&nbsp;'Might do a little looking tomorrow......<br><br>Sorry;^) <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
thanks anyways man..<br><br><br>Leo
 
found a few crumbs.....<br>There is a module, 'Net::Telnet' that may be what you are looking for......has this description.....<br><FONT FACE=monospace><br>Net::Telnet allows you to make client connections to a TCP port<br>&nbsp;&nbsp;&nbsp;&nbsp;and do network I/O, especially to a port using the TELNET<br>&nbsp;&nbsp;&nbsp;&nbsp;protocol.&nbsp;&nbsp;Simple I/O methods such as print, get, and getline are<br>&nbsp;&nbsp;&nbsp;&nbsp;provided.&nbsp;&nbsp;More sophisticated interactive features are provided<br>&nbsp;&nbsp;&nbsp;&nbsp;because connecting to a TELNET port ultimately means communicating<br>&nbsp;&nbsp;&nbsp;&nbsp;with a program designed for human interaction.&nbsp;&nbsp;These interactive<br>&nbsp;&nbsp;&nbsp;&nbsp;features include the ability to specify a timeout and to wait for<br>&nbsp;&nbsp;&nbsp;&nbsp;patterns to appear in the input stream, such as the prompt from a<br>&nbsp;&nbsp;&nbsp;&nbsp;shell.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Here's an example that prints who's logged-on to the remote host<br>&nbsp;&nbsp;&nbsp;&nbsp;sparky.&nbsp;&nbsp;In addition to a username and password, you must also<br>&nbsp;&nbsp;&nbsp;&nbsp;know the user's shell prompt, which for this example is bash$<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;use Net::Telnet ();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$t = new Net::Telnet (Timeout =&gt; 10,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Prompt =&gt; '/bash\$ $/');<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$t-&gt;open(&quot;sparky&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$t-&gt;login($username, $passwd);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@lines = $t-&gt;cmd(&quot;/usr/bin/who&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print @lines;<br></font><br><br>See <A HREF=" TARGET="_new"> like it will do the 'who's logged on trick' and may be useful for 'uptime'.<br>This looks like fun....I may have to play with this one a little.&nbsp;&nbsp;If I get around to it, I'll let you know.<br><br>'hope this helps.....good luck<br><br><br> <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
First answer was close actually, there are remote versions of <FONT FACE=monospace><b>who</font></b> and <FONT FACE=monospace><b>uptime</font></b> called <FONT FACE=monospace><b>rwho</font></b> and <FONT FACE=monospace><b>ruptime</font></b>.<br><br>The services <FONT FACE=monospace><b>rwhod</font></b> and <FONT FACE=monospace><b>ruptimed</font></b> need to be running on the remote machine first and, in some environments, <FONT FACE=monospace><b>rwhod</font></b> could be a security risk as it gives you a list of users on a remote machine and, therefore, a starting point for unauthorised access perhaps.<br><br>Look at <FONT FACE=monospace><b>man ruptime</font></b> and <FONT FACE=monospace><b>man rwho</font></b> for some more info. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
thanks alot fellas...&nbsp;&nbsp;How about how many people logged on the server, would that be easier than to get who's logged on?&nbsp;&nbsp;let me know, and again thanks...
 
Oh another thing too is that, the server that Im trying to find all this information on is a NT machine.&nbsp;&nbsp;Now the rwho and the ruptime commands will not work due to this.&nbsp;&nbsp;Correct?&nbsp;&nbsp;Or else theres a way to have unix talk to NT without some middle man then fine.&nbsp;&nbsp;Now the Net::Telnet module I dont want to have to enter no username and password to get to this info, cause this script will be viewable to everyone on the network...
 
leo2180,<br><br>I've done some searching on CPAN (from <A HREF=" TARGET="_new"> and couldn't find anything relevant.<br><br>I was looking to see if someone had written a perl version of rwhod and or ruptimed that would run on NT - but nope, not as far as I could see.<br><br>It would certainly be <i>possible</i> to write your own versions of these UNIX daemons in VB or VC. That would require expertise in (at least) two areas, TCP/IP and Win32API, and would not be trivial. You would have to have a <i>pressing</i> need for these functions to justify writing them yourself.<br><br>Sorry I can't be of more help, if you still need to do this the best approach might be to look for a commercial package that implements Unix-Type services for NT. As far as I remember the Microsoft Unix package for NT does not include them but it's worth checking.<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top