I have data on one server, which is part of an ever-growing log file. I need to divert this log and grep some information, and then send this to another server for php to be inserted into the database. A computer that has a log cannot be allowed to access the database. I have tried this so far, but my bash command syntax is incorrect, and I cannot figure out if this is the way to do this, or if there is a better way? Netcat was another thought ...
monitor.sh
#!/bin/sh
tail -f /usr/local/log/thelog.log | grep -B1 "ABC=" > /usr/local/log/output.log;
while inotifywait -e modify /usr/local/log/output.log; do
sleep 10;
php /usr/bin/send.php;
done
send.php
<?php
$data = 'tail -n 3 /usr/local/log/output.log';
$url = 'http://www.blahblah.com/logtodb.php';
$data = str_replace("A", "", $data);
$data = str_replace("B=", "", $data);
$data = str_replace("C=", "", $data);
$data = str_replace("D=", "", $data);
$fields = array(
'data'=>urlencode($data)d,
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
$result = curl_exec($ch);
curl_close($ch);
A>
logtodb.php reads a message
source
share