- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script/AWK help
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
Forums
Discussions
Discussions
Discussions
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
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
11-02-2004 11:12 PM
11-02-2004 11:12 PM
I am trying to work out a script but not getting the result I want. Maybe you guys can help:
I have a list that contains:
Start month, Start day, Start Hour, Stop Month, Stop day, Stop Hour.
Like next example:
3 29 6 3 29 6
3 29 15 3 29 17
3 29 17 3 29 17
3 29 17 3 29 17
3 29 17 3 29 17
3 29 17 3 29 17
3 29 17 3 29 18
3 29 17 3 31 18
3 29 18 3 29 18
3 29 18 3 29 18
4 1 23 4 1 23
4 1 23 4 1 23
4 1 23 4 1 23
4 1 23 4 1 23
4 1 23 4 2 0
4 2 0 4 2 0
4 2 0 4 2 0
Al these timing represent the start and stop of an application.
I like to figure out how many concurent users I have on an hourly basis on each day i have. So if a user runs the application for 2 day's it will be counted for 1 user per hour during run day's:
The result must look like:
"Month" "day" "hour" "count of concurent users"
3 29 6 2
3 29 7 4
3 29 8 1
...
...
4 1 0 4
etc.
Hope you can help out.
Regards,
Peter
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2004 01:12 AM
11-03-2004 01:12 AM
Re: Script/AWK help
could you be more precise about getting your desired output
How do you get to your "3 29 8 1" output for example ?
Regards
Franky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2004 01:57 AM
11-03-2004 01:57 AM
Re: Script/AWK help
Your input data's are dealing with starting / stopping time of application. No user details there.
Can your elaborate on your result more.
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2004 02:13 AM
11-03-2004 02:13 AM
SolutionI think you are looking for something like this perl script:
use Time::Local;
while (<>) {
($bm, $bd, $bh, $em, $ed, $eh) = split;
$time = timelocal(0,0,$bh,$bd,$bm-1,2004);
$end = timelocal(0,0,$eh,$ed,$em-1,2004);
while ($time < $end) {
($sec,$min,$hour,$mday,$mon,$year) = localtime $time;
$key = sprintf ("%02d %02d %02d", $mon+1, $mday, $hour);
$usage{$key}++;
$time +=3600;
}
}
foreach $time (sort keys %usage) {
print "$time $usage{$time}\n";
}
For each data line it takes each begin and end time and converts it to seconds.
Then it adds one to the array entry for the start second for each hour in the range.
When all lines are doen it reports the accumulate users for each start hour it ever touched.
With this input:
3 30 6 3 30 16
3 30 14 3 30 17
3 30 18 3 30 19
3 30 13 4 01 18
4 1 10 4 1 23
4 1 20 4 1 21
The output becomes:
03 30 06 1
03 30 07 1
03 30 08 1
03 30 09 1
03 30 10 1
03 30 11 1
03 30 12 1
03 30 13 2
03 30 14 3
03 30 15 3
03 30 16 2
03 30 17 1
03 30 18 2
03 30 19 1
03 30 20 1
:
04 01 09 1
04 01 10 2
04 01 11 2
04 01 12 2
04 01 13 2
04 01 14 2
04 01 15 2
04 01 16 2
04 01 17 2
04 01 18 1
04 01 19 1
04 01 20 2
04 01 21 1
04 01 22 1
Met vriendelijke groetjes,
En veel geluk er mee!
:-).
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2004 02:37 AM
11-03-2004 02:37 AM
Re: Script/AWK help
It looks to me that you got the correct output from my lousy input. The input file I've got is very large so I just cut and pasted some small part. I will test your solution tomorrow because I am in a meeting right now. Thanks anyway.
Franky,
The output have to name the number of runs of an application within that hour of a day.
Muthukumar,
I have user data in this file, but it does not interest me at the moment because the same user can run multiple session of this application. The stats show them per session as one row.
Thanks all and I report back tomorrow,
Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2004 06:01 AM
11-03-2004 06:01 AM
Re: Script/AWK help
:-)
My biggest problem was that the suggested output did not line up with the suggested input. That, plus the fact that the sample input consisted mostly of 'null' records (usage less than 1 full hour?).
btw....
Just in case anyone ever needs a thing smilar to this being year-end resilient...
Here is a tweak that will make that happen.
(Also, it should really use the actual year ,not my hardcoded 2004, to deal with leap years properly :-)
-------------------- perl script ----------
use Time::Local;
while (<>) {
($bm, $bd, $bh, $em, $ed, $eh) = split;
$time = timelocal(0,0,$bh,$bd,$bm-1,2004);
$end = timelocal(0,0,$eh,$ed,$em-1,($em<$bm)? 2005: 2004);
while ($time < $end) {
($sec,$min,$hour,$mday,$mon,$year) = localtime $time;
$key = sprintf ("%1d %02d %02d %02d", $year-104,$mon+1, $mday, $hour);
$usage{$key}++;
$time +=3600;
}
}
foreach $time (sort keys %usage) {
print "$time $usage{$time}\n";
}
---------------------- sample input --------
3 31 20 3 31 23
3 31 18 3 31 22
3 31 21 4 01 6
12 31 21 01 01 01
12 31 22 12 31 23
------output for that sample input --------
0 03 31 18 1
0 03 31 19 1
0 03 31 20 2
0 03 31 21 3
0 03 31 22 2
0 03 31 23 1
0 04 01 00 1
0 04 01 01 1
0 04 01 02 1
0 04 01 03 1
0 04 01 04 1
0 04 01 05 1
0 12 31 21 1
0 12 31 22 2
0 12 31 23 1
1 01 01 00 1
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2004 07:23 PM
11-04-2004 07:23 PM
Re: Script/AWK help
Your scripts work fine. There is one remark. You already mentioned it in the second post, but the times that an application runs within the same hour needs also be counted for that hour.
With this script these stats are not comming back in the output.
Thanks anyway because I would not have been succesful writing this myself. I will try to fix the counts of less then 1 hour runs.
Regards(vriendelijke groet),
Peter