- Code: Select all
#!/usr/bin/perl -w
################################################################
# Program: auto-update
# Programmer: ZiaTioN
# Requires: apt for Red Hat/Fedora
#
# This app does nightly checks for upgradable system packages.
# Simply drop this program in your cron.daily directory
# and set to executable (chmod +x).
#
# Note*
# This could cause issues or loss of service, use at your own
# risk. If a package is updated and has problems you might not
# even be aware of the outage until hours (or days) later.
#
###############################################################
use strict;
my $timestamp = `date`;
my @time = split(/ /, $timestamp);
my $file = $time[2]."-".$time[1]."-".$time[5];
my $create_log = "/var/log/system-update/$file";
my $grab_list = `apt-get -y update`;
my $update_status = `apt-get -y dist-upgrade`;
my $clean = `apt-get -y clean`;
my $timestamp2 = `date`;
open (FILE, ">>$create_log") || die "Cannot open $create_log\n";
print FILE "Log started at: ".$timestamp,"\n\n";
print FILE "###################\n";
print FILE "### List Status ###\n";
print FILE "###################\n";
print FILE $grab_list,"\n\n";
print FILE "##############################\n";
print FILE "### Package Upgrade Status ###\n";
print FILE "##############################\n";
print FILE $update_status,"\n\n";
print FILE "#######################\n";
print FILE "### Clean Up Status ###\n";
print FILE "#######################\n";
if ($clean eq "") {
print FILE "Cleanup was successfull!\n\n";
}else{
print FILE $clean,"\n\n";
}
print FILE "Log ended at: ".$timestamp2,"\n";
close(FILE);
You might need to customize the file path in the value for "$create_log" to reflect where you would like to log the results. If you like the path I have the directory "system-update" will need to be created inside "/var/log".
Just drop this little guy into "cron.daily" and forget about it. By default cron.daily will execute this script around 4:02 AM (depending on how many cron jobs you have in daily) every day.
Edited:
I added the "clean" and I hope you do not mind but I also kinda adopted your header style Void Main.


