Skip to content

Instantly share code, notes, and snippets.

@jetbalsa
Created December 4, 2017 18:36
Show Gist options
  • Save jetbalsa/8945158df469624b3b279c4218296957 to your computer and use it in GitHub Desktop.
Save jetbalsa/8945158df469624b3b279c4218296957 to your computer and use it in GitHub Desktop.
<?php
$server = 'tcp://efnet.port80.se';
$port = 6667;
$pass = '';
$nick = 'at-' . gethostname(); // FIX IF HOSTNAME != rysnc hostname, DO THE SAME FOR BELOW
$channel = '#rsync-status';
function send( $conn, $msg )
{
echo "--> {$msg}\n";
return fwrite( $conn, $msg . "\n" );
}
$connection = fsockopen($server, $port, $errno, $errstr);
if ( ! $connection)
{
die("$errstr ($errno)\n");
}
send( $connection, sprintf("PASS %s", $pass) );
send( $connection, 'USER username "1" "1" :username_again');
send( $connection, sprintf("NICK %s", $nick) );
//send( $connection, sprintf("JOIN %s", $channel) ); // Can't join yet...
$joined = false;
while ( $input = trim( fgets( $connection ) ) )
{
stream_set_timeout( $connection, 3600 );
print $input . "\n";
// Join after all is well
if(strpos($input, "266") AND ! $joined)
{
send( $connection, sprintf("JOIN %s", $channel));
$joined = TRUE;
continue;
}
// Keep alive
if(preg_match("|^PING :(.*)$|i", $input, $matches))
{
echo "[ SERVER PING {$matches[1]} ]\n";
send( $connection, "PONG :{$matches[1]}" );
$f = './'; // EDIT THIS TO POINT TO THE FS DIR YOU WANT TO WATCH
$io = popen ( '/usr/bin/du -sk ' . $f, 'r' );
$size = fgets ( $io, 4096);
$size = substr ( $size, 0, strpos ( $size, "\t" ) );
pclose ( $io );
$free = 1e+12 - $size; // SET TO 1TB, CHANGE TO SET FS SIZE
send( $connection, "PRIVMSG $channel :[" . gethostname() . "] Free: " . $free . " bytes");
// CHANGE BELOW SIZE TO SET ALERT SIZE!
if($free < 1e+9){send( $connection, "PRIVMSG $channel :[" . gethostname() . "] ALERT, LOW SPACE JRWR"); }
continue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment