Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Portage Update & Report Script (PHP CLI)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
apokalyptik
n00b
n00b


Joined: 18 Jun 2002
Posts: 62

PostPosted: Tue Aug 20, 2002 4:15 pm    Post subject: Portage Update & Report Script (PHP CLI) Reply with quote

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/
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum