Tuesday, August 30, 2011

php script date and grep

SkyHi @ Tuesday, August 30, 2011
<?php

$mail_to_array = array("sysadmin@sample.net","admin@sample.net");
$mail_log_path = "/var/log/maillog";

echo "Producing filtered maillog..";

$generated_date_month = date("M");
$generated_date_day = date("j");



if(strlen($generated_date_day) == 1) {
    $gen_date = "$generated_date_month  $generated_date_day";
}else {
    $gen_date = "$generated_date_month $generated_date_day";
}

$execution_string = "grep unknown $mail_log_path | grep '$gen_date' > /tmp/.unknownhack";
exec($execution_string);





$command = "mail -s '[Unknown_user_hack potato] $HOSTNAME - date()' sysadmin@sample.net < /tmp/.unknownhack";
exec($command);

?>