?
Solved

Using command lines

Posted on 1998-10-07
3
Medium Priority
?
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 210 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans
Suggested Courses

743 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