Editing
Infrastructure Machines
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== process flow tools ==== <pre>mkdir /usr/home/flowbin mkdir /usr/home/working</pre> Install modules: <pre>cd /usr/ports/devel/p5-Date-Calc make install clean cd /usr/ports/mail/p5-Mail-Sendmail make install clean</pre> Queue script: <pre> cat > /usr/home/flowbin/queue.pl #!/usr/bin/perl use strict; BEGIN { push @INC, "/usr/home/flowbin"; } use date; my $flowbase = "/usr/home/flows"; #my $flowqueue = "/usr/home/queue"; my $flowqueue = "/usr/home/working"; my ($date, $time) = date::CurrentDateTime(); my $flowdir = mkFlowDir($date); `mv $flowdir/ft-* $flowqueue`; if (date::DateWindow($date, $time, $date, "00:00:00", 600)) { my $newdate = date::AddDays($date, -1); my $flowdir = mkFlowDir($newdate); `mv $flowdir/ft-* $flowqueue`; } sub mkFlowDir { my $date = shift; $date =~ /([0-9]{4}-[0-9]{2})/; my $yearmonth = $1; return "$flowbase/$yearmonth/$date"; } </pre> Date.pm module: <pre> cat > /usr/home/flowbin/date.pm #!/usr/local/bin/perl # # $Header: /usr/cvs/newgw/lib/date.pm,v 1.2 2003/11/24 17:06:02 glenn Exp $ # # Copyright (c) 2001, 2002, 2003 # e-Monitoring Networks, Inc. All rights reserved. # # # # date.pl - Higher level functions written on top of Date::Calc package date; use strict; use Date::Calc qw(:all); sub DayDiff { #calculate the difference in days from two dates my $date1 = shift; my $date2 = shift; my ($year1, $month1, $day1) = &DateToymd($date1); my ($year2, $month2, $day2) = &DateToymd($date2); my $diff = &Delta_Days($year1, $month1, $day1, $year2, $month2, $day2); return $diff; } sub AddDays { #adds specified number of days to the supplied date my $date = shift; my $days = shift; my ($year, $month, $day) = &DateToymd($date); my ($nyear, $nmonth, $nday) = &Add_Delta_Days($year, $month, $day, $days); my $ndate = &ymdToDate($nyear, $nmonth, $nday); return $ndate; } sub AddHours { #adds specified number of hours to the supplied date and time my $date = shift; my $time = shift; my $addhours = shift; my $adddays = 0; if (abs($addhours / 24) >= 1) { $adddays = int($addhours / 24); $addhours -= $adddays * 24; } my ($year, $month, $day) = &DateToymd($date); my ($hour, $minute, $second) = &TimeTohms($time); my ($ny, $nm, $nd, $nh, $nmin, $ns) = &Add_Delta_DHMS($year, $month, $day, $hour, $minute, $second, $adddays, $addhours, 0, 0); my $ndate = &ymdToDate($ny, $nm, $nd); my $ntime = &hmsToTime($nh, $nmin, $ns); return $ndate, $ntime; } sub AddMinutes { my $date = shift; my $time = shift; my $minutes = shift; my ($year, $month, $day) = &DateToymd($date); my ($hour, $minute, $second) = &TimeTohms($time); my ($ny, $nm, $nd, $nh, $nmin, $ns) = &Add_Delta_DHMS($year, $month, $day, $hour, $minute, $second, 0, 0, $minutes, 0); my $ndate = &ymdToDate($ny, $nm, $nd); my $ntime = &hmsToTime($nh, $nmin, $ns); return $ndate, $ntime; } sub CurrentDateTime { #return the current date and time my ($y, $m, $d, $h, $min, $s, $z, $z, $z) = &System_Clock; my $date = &ymdToDate($y, $m, $d); my $time = &hmsToTime($h, $min, $s); return $date, $time; } sub Currentymd { #return the current year, month and day as separate variables my ($y, $m, $d, $h, $min, $s, $z, $z, $z) = &System_Clock; return $y, $m, $d; } sub DateToymd { #takes a date and returns year, month, day as individual values my $date = shift; if ($date =~ /([0-9]{4})-([0-9]{2})-([0-9]{2})/) { my $day = $3; my $month = $2; my $year = $1; return $year, $month, $day; } return undef; } sub TimeTohms { #takes a time and return hours minutes and seconds as individual values my $time = shift; if ($time =~ /([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})/) { my $hour = $1; my $minute = $2; my $second = $3; if ($hour !~ /[0-9]{2}/) { $hour = "0$hour"; } if ($minute !~ /[0-9]{2}/) { $minute = "0$minute"; } if ($second !~ /[0-9]{2}/) { $second = "0$second"; } return $hour, $minute, $second; } return undef; } sub ymdToDate { #takes year, month, day and assembles them into our date format my $year = shift; my $month = shift; my $day = shift; if (defined($year) && defined($month) && defined ($day)) { $month = sprintf("%02d", $month); $day = sprintf("%02d", $day); return "$year-$month-$day"; } return undef; } sub hmsToTime { #takes hour minute and second and assembles them into our time format my $hour = shift; my $minute = shift; my $second = shift; if (defined($hour) && defined($minute) && defined ($second)) { if ($hour !~ /[0-9]{2}/) { $hour = "0$hour"; } if ($minute !~ /[0-9]{2}/) { $minute = "0$minute"; } if ($second !~ /[0-9]{2}/) { $second = "0$second"; } return sprintf ("%02d:%02d:%02d", $hour, $minute, $second); } return undef; } sub CompareDates { #compares two date and time pairs my $date1 = shift; my $time1 = shift; my $date2 = shift; my $time2 = shift; my ($year1, $month1, $day1) = &DateToymd($date1); my ($hour1, $minute1, $second1) = &TimeTohms($time1); my ($year2, $month2, $day2) = &DateToymd($date2); my ($hour2, $minute2, $second2) = &TimeTohms($time2); # &debug("$year1, $month1, $day1, $year2, $month2, $day2"); my $days = &Delta_Days($year1, $month1, $day1, $year2, $month2, $day2); if ($days > 0) { return 1;} if ($days < 0) { return -1;} if ($days == 0) { #same day, compare times my $seconds1 = $second1 + (60 * $minute1) + (3600 * $hour1); my $seconds2 = $second2 + (60 * $minute2) + (3600 * $hour2); if ($seconds1 < $seconds2) { return 1;} if ($seconds1 > $seconds2) { return -1;} if ($seconds1 == $seconds2) { return 0;} } return undef; } sub DateWindow { #compares two date time pairs to see if they are < X seconds apart my $date1 = shift; my $time1 = shift; my $date2 = shift; my $time2 = shift; my $window = shift; my ($year1, $month1, $day1) = &DateToymd($date1); my ($hour1, $minute1, $second1) = &TimeTohms($time1); my ($year2, $month2, $day2) = &DateToymd($date2); my ($hour2, $minute2, $second2) = &TimeTohms($time2); my ($day, $hour, $minute, $second) = &Delta_DHMS($year1, $month1, $day1, $hour1, $minute1, $second1, $year2, $month2, $day2, $hour2, $minute2, $second2); $minute *= 60; $hour *= 3600; $day *= 86400; my $total = $second + $minute + $hour + $day; if (abs($total) < $window) { return 1; } return 0; } sub CheckDateOrder { #takes three dates/times, returns true if they are in chronological order my $date1 = shift; my $time1 = shift; my $date2 = shift; my $time2 = shift; my $date3 = shift; my $time3 = shift; if (&CompareDates($date1, $time1, $date2, $time2) == -1) { return 0; } if (&CompareDates($date2, $time2, $date3, $time3) == -1) { return 0; } return 1; } sub EpochSeconds { #calculates number of seconds since the epoch for the given date/time my $date = shift; my $time = shift; my ($year, $month, $day) = &DateToymd($date); my ($hour, $minute, $second) = &TimeTohms($time); my ($d, $h, $m, $s) = &Delta_DHMS(1970, 1, 1, 0, 0, 0, $year, $month, $day, $hour, $minute, $second); my $seconds = $s + (60 * $m) + (3600 * $h) + (86400 * $d); return $seconds; } sub SecondsToDateTime { #converts seconds since epoch to date/time my $seconds = shift; my $days = int($seconds / 86400); $seconds -= $days * 86400; my $hours = int($seconds / 3600); $seconds -= $hours * 3600; my $minutes = int($seconds / 60); $seconds -= $minutes * 60; my ($year, $month, $day, $hour, $minute, $second) = &Add_Delta_DHMS(1970, 1, 1, 0, 0, 0, $days, $hours, $minutes, $seconds); $month = sprintf("%02d", $month); $day = sprintf("%02d", $day); $hour = sprintf("%02d", $hour); $minute = sprintf("%02d", $minute); $second = sprintf("%02d", $second); return "$year-$month-$day", "$hour:$minute:$second"; } sub DateToDayName { my $date = shift; my ($year, $month, $day) = &DateToymd($date); my $name = &Day_of_Week_to_Text(&Day_of_Week($year, $month, $day)); $name =~ /^[A-Za-z]{3}/; $name = $&; return $name; } sub ValiDate { return @_; } sub CheckBusinessDay { # checks to see if date is business day. 1=yes, 0=no my $date = shift; my ($year, $month, $day) = &DateToymd($date); if (Day_of_Week($year,$month,$day) < 6) { return 1; } else { return 0; } } 1; #don't remove this line </pre> chmod 0700 /usr/home/flowbin/queue.pl Setup cronjob: <pre>crontab -e #move flow data into the queue 1,16,31,46 * * * * /usr/home/flowbin/queue.pl</pre>
Summary:
Please note that all contributions to JCWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
JCWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information