Solved

Using command lines

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now