473,413 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

how to get a line of text as an array without white space?


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
Then I needed to this data broken up and stored in the database, each
field. I looped through this stuff, taking on line at a time, and each
line I would hit with explode, like this:

$arrayOfFields = explode(" ", $stringOfOneLine);
Unfortunetly, this gives me an array that has lots of blank rows because
every white space becomes a row in the array and, as you can see, there
is a lot of white space.

So I loop through the array and take out all the empty rows, but damn,
this is tedious and clumsy. Is there a better way?

I also struggle with the opposite problem:

Bee/878037001068/878037001068_01

The fields run together. Can anyone think of a way to separate them?
Jul 26 '08 #1
5 1600
Lawrence Krubner wrote:
>
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
Then I needed to this data broken up and stored in the database, each
field. I looped through this stuff, taking on line at a time, and each
line I would hit with explode, like this:

$arrayOfFields = explode(" ", $stringOfOneLine);
Unfortunetly, this gives me an array that has lots of blank rows because
every white space becomes a row in the array and, as you can see, there
is a lot of white space.

So I loop through the array and take out all the empty rows, but damn,
this is tedious and clumsy. Is there a better way?

I also struggle with the opposite problem:

Bee/878037001068/878037001068_01

The fields run together. Can anyone think of a way to separate them?
Sounds like you're approaching things the wrong way. If you need to
track ftp uploads, you should be hooking into the ftpd daemon. You
won't be able to do it in PHP, though.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jul 27 '08 #2

"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
Jul 27 '08 #3
..oO(Lawrence Krubner)
>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
Just curious: What does this tell you about FTP uploads? Additionally
lsof might output some more stuff than you actually want, so it might
make sense to pass some explicit command line options to it.
>Then I needed to this data broken up and stored in the database, each
field. I looped through this stuff, taking on line at a time, and each
line I would hit with explode, like this:

$arrayOfFields = explode(" ", $stringOfOneLine);
Unfortunetly, this gives me an array that has lots of blank rows because
every white space becomes a row in the array and, as you can see, there
is a lot of white space.
One option to remove empty array entries is array_filter(), but in this
case preg_split() would be better:

$arrayOfFields = preg_split('/ +/', $stringOfOneLine);
>So I loop through the array and take out all the empty rows, but damn,
this is tedious and clumsy. Is there a better way?

I also struggle with the opposite problem:

Bee/878037001068/878037001068_01

The fields run together. Can anyone think of a way to separate them?
Where does this come from?

Micha
Jul 27 '08 #4
On Jul 27, 12:49 am, Lawrence Krubner <lawre...@krubner.comwrote:
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
What do you think you're measuring?

(because its not file uploads)

C.
Jul 27 '08 #5
Lawrence Krubner wrote:
>
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
Then I needed to this data broken up and stored in the database, each
field. I looped through this stuff, taking on line at a time, and each
line I would hit with explode, like this:

$arrayOfFields = explode(" ", $stringOfOneLine);
Unfortunetly, this gives me an array that has lots of blank rows because
every white space becomes a row in the array and, as you can see, there
is a lot of white space.

So I loop through the array and take out all the empty rows, but damn,
this is tedious and clumsy. Is there a better way?

I also struggle with the opposite problem:

Bee/878037001068/878037001068_01

The fields run together. Can anyone think of a way to separate them?

Exactly what are you measuring doing this? If this job runs every 5
minutes, what happens when an upload starts at minute 6 and completes at
minute 9?

lsof will only tell you the current open files, not files that may have
been recently uploaded.

And why not use the log files provided. See the following link for a
starting place...
http://mirror.centos.org/centos/4/do...ftpd-conf.html
Jul 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jerry Sievers | last post by:
tried to avoid using PRE in the page markup and instead used DIV CLASS=foo and assigned the white-space pre property to it. have some reports already that text is not showing as preformatted. ...
5
by: Applebrown | last post by:
Hello, basically, I'm just learning intermediate CSS and trying to convert my old table webpage completely to CSS. Hoorah, right? Well, it's not quite going as planned. It's an extremely simple...
0
by: Mark Moore | last post by:
I'm trying to layout a couple text input fields and their corresponding labels without using a table. When I was trying to debug my understanding of CSS, I was *very* surprised to see that span's...
5
by: Michael Shell | last post by:
Greetings, Consider the XHTML document attached at the end of this post. When viewed under Firefox 1.0.5 on Linux, highlighting and pasting (into a text editor) the <pre> tag listing will...
38
by: Xah Lee | last post by:
sometimes i wish to add white space in <p> as to achived effects similar to tab. what should i do? using empty image seems the sure way but rather complicated. (and dosen't change size with...
0
by: TR | last post by:
I am adding a Panel to my page at runtime so: '//note that P is another container Panel Dim MyPanel As New System.Web.UI.WebControls.Panel MyPanel.CssClass = "MYPANEL" MyPanel.ID = "p100"...
12
by: JA | last post by:
Is there a way to remove all the white space in the fields? I have been using Find-and-replace - looking for 2 or 3 or 4 or 10 spaces and replacing them with none. I don't want to replace single...
4
by: asnowfall | last post by:
If I have white space in the <atag, IE interpretes it as line break. I tried setting "whie-space: pre" and it did not seem to affect. Here is a sample. ...
12
by: snow | last post by:
Hi All, I noticed if file path has a white space, for example "C:\my document \test.txt", the function File.Exists(filePath) always return false in release mode. How could I make this function...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.