Listing 6. Symbolic Link Program for cron
#!/usr/bin/perl -wT
# A file that creates a symbolic link to the
# file for today. This can be run in cron.
use strict;
use vars qw($destination $today_file @date $year $month $date);
use diagnostics;
# Set the symlink name
$destination = "/today.html";
# Get today's date, and set a filename based on it
@date = localtime(time);
$year = $date[5];
$month = $date[4];
$date = $date[3];
$today_file = "file-$year-$month-$date.html";
if (-f $today_file)
{
# Create a symbolic link to today's file
$successful = symlink($file, $today);
# Indicate if there was a problem
if ($successful)
{
print "Successfully created link $today -> $file";
}
else
{
print "Problem creating symlink"
unless $successful;
}
}
Copyright © 1994 - 2019 Linux Journal. All rights reserved.