apokalyptik n00b
Joined: 18 Jun 2002 Posts: 62
|
Posted: Tue Aug 20, 2002 4:15 pm Post subject: Portage Update & Report Script (PHP CLI) |
|
|
I'm not sure that this is the kind of thing people are looking for here... but it sure saves me time when managing multiple servers!
Code: | #!/usr/bin/php -f
<?php
/*******************************************************************
* Script: Portage Update & Report Script *
* OS: Gentoo Linux 1.2 *
* Tested With: Linux (i686) *
* Version: 0.1 *
* Author: Demitrious Kelly (apokalyptik@apokalyptik.com) *
*******************************************************************
* Purpose: Simply updates the ports collection and sends an *
* e-mail to those concerned about what is - or isnt - in need of *
* updating *
*******************************************************************
* Usage: run at desired interval as a cron job e.g: *
* 0 0 * * * /bin/bash -c /root/scripts/update.php 2> /dev/null *
*******************************************************************/
/* The subject of the e-mail that will be sent out... */
$subject='Subject: www.server.com - checking for updates';
/* you may have as many, or as few, $notify[] e-mail addresses as */
/* you wish... Each will get an e-mail */
$notify[]='admin@server.com';
$notify[]='owner@server.com';
/* Sets the execution Time Limit for the script... default: 1 hour */
set_time_limit(3600);
$msg.='Updating the source tree...'.chr(10);
/* Update the source Tree */
$null=`/usr/bin/emerge rsync`.chr(10).chr(10);
$msg.='Checking for updateable packages...'.chr(10).chr(10);
/* check for packages which need updating */
$msg.=`/usr/bin/emerge --update world -p`.chr(10).chr(10);
$msg.='Completed!';
/* Strip out ANSI code */
$msg=str_replace(chr(8), '', $msg);
$msg=str_replace(chr(27), '', $msg);
$msg=str_replace('\|/-', '', $msg);
$msg=str_replace('\|/', '', $msg);
$msg=str_replace('|/-', '', $msg);
$msg=str_replace('/-', '', $msg);
$msg=str_replace('[36;01mU[0m ]', 'U ]', $msg);
/* Send E-Mails */
foreach ( $notify as $e ) {
mail($e, $subject, $msg, "Reply-To: root@server.com");
}
?> |
_________________ http://www.apokalyptik.com/ |
|