"Lawrence Krubner" <la******@krubner.comwrote in message
news:1I******************************@earthlink.co m...
>
I'm suppose to track FTP uploads to the server. I've got a cron script,
written in PHP, that runs every 5 minutes and which does the command
lsof | grep vsftpd
This gives me a big file that has data like this in it:
vsftpd 12316 lawrence cwd DIR 9,2 4096
20938763 /data/ftp/lawrence_krubner
vsftpd 12316 lawrence rtd DIR 9,2 4096
20938763 /data/ftp/lawrence_krubner
i'm going to stick to answering your question rather than telling you it
can't be done in php...like some other morons here. :)
I also struggle with the opposite problem:
Bee/878037001068/878037001068_01
not sure what you means by that one.
anyway, i couldn't tell if the output you pasted here is a single line entry
starting with 'vsftpd' and ending with 'lawrence_krubner' (case 'A') or, if
there were two related rows where a new row of data started after '4096' and
'lawrence_krubner' (case 'B'). there was a soft-return (a \n) after 4096
when i copied it into my test script...so, i assume the latter. if not, let
me know. either way, this should work...
=============
<?
$contents = "vsftpd 12316 lawrence rtd DIR 9,2
4096
20938763 /data/ftp/lawrence_krubner"; // case 'B'
$patterns = array(
'/\r?\n/' , // force unix \n
'/^/' , // beginning of line
'/$/' , // end of line
'/ +/' // spaces
);
$replacements = array(
"\"\n\"" , // unix nl w/ encapsulation
'"' , // start line with quote
'"' , // end line with quote
'", "' // encapsulate fields
);
$contents = preg_replace($patterns, $replacements, $contents);
?>
=============
this will turn your output file contents into a csv format. if case 'A', you
can use php's built-in cvs parsing functions to help you out or look at the
example below. if case 'B', you'll have to keep track of what row (even or
odd) you are processing to know what fields to expect from the row and what
positions the fields will be in.
i digress. at this point, you've gotten a format you can work with and
forced a unix \n to separate your rows. manually break it out into rows and
from there, into fields:
=============
<?
$contents = explode("\n", $contents); // file into array of rows
foreach ($contents as $row)
{
$row = substr($row, 1); // strip initial quote
$row = substr($row, 0, -1); // strip ending guote
$row = explode('", "', $row); // row into array of fields
foreach ($row as $index =$column)
{
echo '<pre style="font:10px;">COLUMN ' . $index . ' = ' . $column .
'</pre>';
}
}
?>
=============
if case 'A', this sample will output:
COLUMN 0 = vsftpd
COLUMN 1 = 12316
COLUMN 2 = lawrence
COLUMN 3 = rtd
COLUMN 4 = DIR
COLUMN 5 = 9,2
COLUMN 6 = 4096
COLUMN 7 = 20938763
COLUMN 8 = /data/ftp/lawrence_krubner
if case 'B', this sample will output:
COLUMN 0 = vsftpd
COLUMN 1 = 12316
COLUMN 2 = lawrence
COLUMN 3 = rtd
COLUMN 4 = DIR
COLUMN 5 = 9,2
COLUMN 6 = 4096
COLUMN 0 = 20938763
COLUMN 1 = /data/ftp/lawrence_krubner
anyway, like i said, i'm not making egotistical assumptions about what
you're trying to do. i'm merely answering the question you asked. i hope it
helps.
cheers