Products & Newsletters
PERL Logger
Tech Tips, March 2010
A Perl of a logger
When it comes to logging a station's stream, there are many products available with a variety of features. But if you're handy with writing scripts, you can create your own. Rob Landry, a contract engineer in Boston, created such a script for one of his clients.
His Perl script records each hour as an MP3 file by capturing the station's Internet stream. Each hour is labeled and placed in a directory for each day (e.g. "wed_dec_16_2009").
#!/usr/bin/perl
# ==> AIRCHECK SCRIPT
sub log {
my $a = shift;
my $time = localtime(time);
if (open (LOG,">>$LOG")) {
print (LOG "$time: $a\n");
close LOG;
}
}
sub purge {
my $a = '';
my @stat = ();
my $ptime = time - 86400 * $RETAIN;
if (opendir (ROOT,$ROOT)) {
while ($a = readdir ROOT) {
@stat = stat("$ROOT/$a");
if ($stat[9] < $ptime) {
if (system("rm -rf $ROOT/$a")) {
&log("FAILED: rm -rf $ROOT/$a");
} else {
&log("$ROOT/$a purged");
}
}
}
closedir ROOT;
}
}
# ==> MAIN PROGRAM
@MON = ('jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec');
@DAY = ('sun','mon','tue','wed','thu','fri','sat','sun');
@HOUR = ('12mid','1am','2am','3am','4am','5am','6am','7am','8am','9am','10am','11am','12noon','1pm','2pm','3pm','4pm','5pm','6pm','7pm','8pm','9pm','10pm','11pm');
$ROOT = '/var/aircheck';
$RETAIN = 60;
$LOG = '/var/aircheck/aircheck.log';
$PERIOD = 3600; # 1 hour
$URL = "http://192.168.0.101:8001/xstream";
if ($a = fork) {
$count = 0;
while ($count < $PERIOD) {
$count++;
sleep 1;
}
kill 9,$a;
wait();
print "exiting\n";
} else {
&purge;
@time = localtime(time);
$wday = $DAY[$time[6]];
$year = 1900 + $time[5];
$mon = $MON[$time[4]];
$day = $time[3];
$hour = $HOUR[$time[2]];
$dir = "$ROOT/$wday\_$mon\_$day\_$year";
if (! (-d $dir)) {system("mkdir $dir")}
exec("wget $URL -O $dir/$hour.mp3");
}
What custom scripts have you developed to handle routine tasks? Share them with us to be posted online.
We need your tips!
Ideas submitted to Tech Tips may be suitable to earn SBE recertification credits.
Do you have a tech tip? Send it to us at radio@RadioMagOnline.com
Acceptable Use Policy blog comments powered by Disqus
[an error occurred while processing this directive]
Today in Radio History
Milestones From Radio's Past
The history of radio broadcasting extends beyond the work of a few famous inventors.
EAS Information More on EAS
FCC Publishes Fifth Report and Order on EAS
The new rules take effect April 30, 2012.
FEMA Releases 2012 Supplemental Guidance Report
The purpose of the document is to promote consistency in policy across Federal grant programs, and to ensure compatibility among Federally funded projects.
EAS/CAP FAQ
Now that FEMA has adopted the CAP1.2 standard, broadcasters are asking questions about the deadline to install equipment and updates to the EAS rules.
NWS XML/Atom Feed for CAP Messages
The feed provides feeds for all US states and territories.
How Much Data in CAP?
Now that the IPAWS OPEN server is on-line, it makes sense to get your CAP-enabled EAS equipment going.
Wallpaper Calendar
Radio 2012 Calendar Wallpaper
Need a calendar for your computer desktop? Use one of ours.
The Wire
A virtual press conference
Information from manufacturers and associations about industry news, products, technology and business announcements.
Current Issue
Inside the Radio Network
Take a peek into Dial Global to see how the syndicator delivers programming to your station.
Browse Back Issues
[an error occurred while processing this directive]Also in the May Issue
Sections


