John Nichel wrote:

Rodney Green wrote:

John Nichel wrote:



Chances are, $buffer has the line break on it when you read it in from the text file. Try striping off whitespace before you write...

while (!feof ($handle)) {
    $buffer = rtrim ( fgets($handle, 1000) );
    fwrite ($fhandle, "chown $buffer:html

http://www.php.net/manual/en/function.rtrim.php


Thanks John! That was the problem.


Rod


Now that I stop and think about it a bit, rtrim() may hurt you here. Since you're using a fread to read the text file, it will read the bytes you tell it (1000), then move on to the next line of code. So if you have a line as such in your text file...

./command --this=that

and the fread() reaches the byte limit on the whitespace after command, it's going to remove that, and you'll end up with....

./command--this=that

You can tell rtim() what characters to strip by doing...

rtrim ( $foo, "\n" );

but I've seen rtrim() strip blank spaces even when this is done. A better way may be to change the way you're reading in the source file; instead of using a fread, you can use file(), which will put each line in an array element...This way, it won't stop reading in the middle of a line....

$fhandle = fopen ("/scripts/thescript.sh" , "a");
$handle = file ( "/scripts/mail_list.txt" );
for ( $i = 0; $i < sizeof ($handle); $i++ ) {
$buffer = rtrim ( $handle[$i] );
fwrite ($fhandle, "chown $buffer:html /scripts/var/spool/mail/$buffer\n", 4096);
}
fclose ($fhandle);


Actually, I'm not having problems with that. The whitespace is still there in between the commands and arguments, etc. I'm using fgets , not fread. Not sure what the difference between the two is but I'll check it out. The problem I am having however is that at the end of the shell script that is created it puts an additional line. It writes the chown command line for all of the users then puts the following line with no user specified.

chown :html /var/spool/mail/

The other lines show up as:
chown rgreen:html /var/spool/mail/rgreen
chown rgreen01:html /var/spool/mail/rgreen01
chown rod:html /var/spool/mail/rod

Any ideas where that extra line is coming from?

thanks again,
Rod

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to