Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using command lines

Posted on 1998-10-07
3
Medium Priority
?
189 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
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

618 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