Solved

Using command lines

Posted on 1998-10-07
3
165 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl script 4 107
crawling gofundme 4 126
Perl string replace for refred url 9 62
PHP pack() : What exactly is meant by signed char and unsigned char? 7 103
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 …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

770 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