LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (http://www.linuxquestions.org/questions/slackware-14/)
-   -   Wrapper script for alienBob's rsync_slackware_patches.sh ? (http://www.linuxquestions.org/questions/slackware-14/wrapper-script-for-alienbobs-rsync_slackware_patches-sh-774696/)

Yalla-One 12-10-2009 05:04 AM

Wrapper script for alienBob's rsync_slackware_patches.sh ?
 
Hi,

I'm currently running rsync_slackware_patches.sh -q against the local mirror on a nightly basis and normally (when there's no patches) it outputs nothing, and when there is a patch, it outputs that entry in the changelog.

What is the best way to approach writing a wrapper-script around the rsync-script in order to email the output of the downloaded patches to me when something is changed and keep quiet when no news?

-y1

zordrak 12-10-2009 05:06 AM

Personally I'd just wrap it up in some perl. Pretty easy to do. Just looking for the last perl email script I wrote..

zordrak 12-10-2009 05:11 AM

Code:

#!/usr/bin/perl

if(dosomelogic()) {
  emaillog();
};


sub emaillog
{
        my $sendmail = "/usr/bin/sendmail -t";
        my $from    = "From: Foo <foo@example.com>\n";
        my $reply_to = "Reply-to: foo\@example.com\n";
        my $subject  = "Subject: Foo output of foo \n";
        my $content  = "\n";
        my $to      = "To: foo\@example.com\n";
        my $cc      = "Cc: bar\@example.com\n";
        my $file    = "/path/to/file/to/email/as/attachment.txt";

        open(FILE, $file) or die "Cannot open attachment";
        while ( <FILE> )
        {
                $content = $content . $_;
        }
        close(FILE);


        open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
        print SENDMAIL $from;
        print SENDMAIL $reply_to;
        print SENDMAIL $subject;
        print SENDMAIL $to;
        print SENDMAIL $cc;
        print SENDMAIL "Content-type: text/plain\n\n";
        print SENDMAIL $content;
        close(SENDMAIL);
}

Then you just need some logic to test whether whatever change you want to test for is present, and call emaillog().

Alien Bob 12-10-2009 07:05 AM

Quote:

Originally Posted by Yalla-One (Post 3786460)
Hi,

I'm currently running rsync_slackware_patches.sh -q against the local mirror on a nightly basis and normally (when there's no patches) it outputs nothing, and when there is a patch, it outputs that entry in the changelog.

What is the best way to approach writing a wrapper-script around the rsync-script in order to email the output of the downloaded patches to me when something is changed and keep quiet when no news?

-y1

It is very easy. I run this script as a cron job every night. One nice feature of cron is that it will capture the output from the programs it runs and sends that text per email to the user account who runs the job.

No need for wrappers.

If root runs that script, then you can add an read mail address as email alias for root in /etc/mail/aliases (and run the command "newaliases" after the edit).

Eric

zordrak 12-10-2009 07:18 AM

^ And that is why alienBOB is the Dutch word for God :)


All times are GMT -5. The time now is 05:35 PM.