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.
Digital Edition
Each Issue as a Digital Edition
Read each issue online in our Digital Edition Format in your Web browser.
EAS Information More on EAS
NWS XML/Atom Feed for CAP Messages
The feed provides feeds for all US states and territories.
Wallpaper Calendar
Radio 2013 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
Noise Elimination at WKSU's Akron News Bureau
This high-visibility and high-traffic area got the full acoustic treatment.
Browse Back Issues
[an error occurred while processing this directive]Also in the May Issue
Sections







