Solved

Using command lines

Posted on 1998-10-07
3
172 Views
Last Modified: 2010-03-05
I want to get the uptime by using the command line :

set `cat /proc/uptime`

and then using the variables $1 and $2

How do I do this in perl??
Writing set `cat /proc/uptime`, gives my a syntax error!!!

How do I use command lines like this???
0
Comment
Question by:lar_jens
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 70 total points
ID: 1205177
using /proc/uptime is rather linux (and a few others) specific.  Since
I don't have a linux box here, and don't offhand know the format here,
the following sample code should do the trick for you.  If not, let me
know.

$a = `cat /proc/uptime`;
$a =~ s/^\s+|\s+$//g;
print "$a\n";
 
@z = split(/\s+/,$a);
for ($i = 0; $i <= $#z; $i++) {
   print "$i\t\"$z[$i]\"\n";
}
 


## Interestingly enough, I'd be willing to be you could do something
## similar by doing:

open(UPTIME, '</proc/uptime');
$a = <UPTIME>;
close(UPTIME);
$a =~ s/^\s+|\s+$//g;
print "$a\n";
 
@z = split(/\s+/,$a);
for ($i = 0; $i <= $#z; $i++) {
   print "$i\t\"$z[$i]\"\n";
}
 

## which is a tad bit more efficient.
0
 
LVL 1

Author Comment

by:lar_jens
ID: 1205178
Adjusted points to 75
0
 
LVL 1

Author Comment

by:lar_jens
ID: 1205179
oki... thx!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question