- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Using df -k on Perl
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2005 09:21 PM
тАО04-04-2005 09:21 PM
I then try and loop through the file and send each line to an aray.
I then want to print out the % field and do a test to see if the disk space is greater than 80% so I can perform a task on that, but for some reason when I split the array using qw(@aray_name), it does not give me any data.
Any advice
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2005 11:17 PM
тАО04-04-2005 11:17 PM
Re: Using df -k on Perl
qw// will Quote Words: any sequence of non blanks is considered a word in that, except the ',' for which you will probably get a warning
what you probably meant was to split up each line into fields, where the fields are seperated by spaces:
my @list = split /\s+/;
In a more full context:
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5] > 80 and print;
}
HTH, Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2005 11:28 PM
тАО04-04-2005 11:28 PM
Re: Using df -k on Perl
I have assigned the array now to a second array and then substituted the % sign with //.
This works, but is there a simpler and quicker way to do so.
I get an error message that 46% is not a numeric value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2005 11:44 PM
тАО04-04-2005 11:44 PM
Re: Using df -k on Perl
That is a bonus for you.
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5] =~ m/(\d+)/ && $1 > 80 and print;
}
is a cleaner way, or you can use the less maintainable way of looking at the value in string context:
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5] =~ m/^([89]\d|1\d\d)%$/ and print;
}
this will match all percentages from 80 and up.
FYI the *dirty* way to get rid of this warning (since you know it is OK) is to (temporarily) disable warning:
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
no warnings;
$f[5] > 80 and print;
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 12:00 AM
тАО04-05-2005 12:00 AM
Re: Using df -k on Perl
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5]=~tr/\%//g and print; ### my changes
}
My goal is to have an output
/usr 88%
/var 94%
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 12:03 AM
тАО04-05-2005 12:03 AM
Re: Using df -k on Perl
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
print "@f[0,5]\n";
}
or
local @ARGV = ("df -k |");
while (<>) {
print +(split/\s+/)[0,5],"\n";
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 12:09 AM
тАО04-05-2005 12:09 AM
Re: Using df -k on Perl
From the command line, that might even shorter look like:
a5:/u/usr/merijn 105 > df -k | perl -anle'print"@F[1,5]"'
Mount %used
/ 17%
/data 57%
/home 8%
/opt 95%
/pro 97%
/stand 26%
/tmp 8%
/u 50%
/usr 86%
/var 13%
/wrk 67%
a5:/u/usr/merijn 106 >
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 01:40 AM
тАО04-05-2005 01:40 AM
Re: Using df -k on Perl
Why can I not do the following
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5]=~tr/\%//g > 80 and print; ### my changes
}
I would like to print all the parttions greater than 80% but in the format
/usr 80%
/var 92%
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 01:49 AM
тАО04-05-2005 01:49 AM
Solutionsecondly because tr/// is not the same as s/// and tr/// does not recognize the /g option (tr/// or the equivalent y/// only know of the options 'c' - complement the search list, 'd' - delete found but unreplaced characters, and 's' - squash duplicate replaced characters.
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5]=~tr/\%//g > 80 and print; ### my changes
}
that's why I gave you the second example
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5] =~ m/(\d+)/ && $1 > 80 and print;
}
but if you prefer to delete the '%' from the original string, you'd better do
local @ARGV = ("df -k |");
while (<>) {
my @f = split /\s+/;
$f[5] =~ tr/%//d && $f[5] > 80 and print;
}
Enjoy, Have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2005 05:50 PM
тАО04-05-2005 05:50 PM
Re: Using df -k on Perl
The first to responses gave me an option to give your help a rating, however I the last few replies there is no option to rate your responses..
If I may ask you what does the pipe do after df -k |.
I have just done a PErl course at HP but it seems I still have a long way to go, as I don't recognise most of the stuff you have shown me
Regards
Steve