Append two lines of text to php.ini in the entire directory tree.e
I am looking to write a script that will read the php.ini files on my web host. If the two lines do exist do nothing. If not append two lines to the end of it then move on to the next directory and open the next php.ini file.
I have the beginning of one that was given to me on another web site but the web site will only allow me to comment on the answer not ask any more, to ask more I would have to start another topic ?! oh well.
what I have almost works. I understand how most of it works but not all. Here it is;
it does work 99.98% but why?
I know the if ! means the first grep needs to be false and the && ! means the second needs to be false if false echo line1 and line2 but whats to determine the placement of those two lines at the end of the file? also how does the done << work ?
I kind understand the find statement. My BASH skills are pretty much limited to navigation and after playing around with the sed command I am a bit weary of diving in head first.
Last edited by Scrutinizer; 09-05-2015 at 10:14 AM..
Reason: code tags
Hi
The first < means read stdin from a file
The construct <( command ) is known as process subtitution and it takes the output of the command and presents it as if it were a file...
A better way to do this would be:
it can also be done with a pipe:
Welcome to forum, following may help you in same. But I don't have system so couldn't test it, please try it and let me know if this helps or for any queries please. Also if you are in Sunos then you could use nawk for same.
NOTE: I have commented mv command above, if you feel command is ok then you can use it.
Probably because the number of embedded spaces is different sometimes.
ie
even though both lines are correct syntax.
Your script might work better if you limit the value of line1 and line2 to just the variable name.
Alternatively, what happens if the line appears twice in the .ini file?
First Thank You for your replies,
made a mockup directory tree then I ran the above code (as a welder/fitter I understand pipes ) worked perfect untill I changed 50M to 40M then I wound up with a bunch of duplicate entries which means if is use it that way I am stuck with those values. So I tried to change it to deal with that. See below;
what I am now trying to do is if grep finds line1 and line 2 to be true then have sed remove them.
the bottom sed command works on a single file in the directory from the command line but I cant figure out how to get to work in the script. when I run it it doesn't error but doesn't remove the lines either.
also what is the $f ?? I see it in scripts I think it is a variable for the file name but if so how is it assigned ?
Last edited by Larrykh465; 09-05-2015 at 03:22 PM..
$f is the name of each file that is processed.
The find command creates a list of file name, that are then read one at a time into the $f variable by the do loop.
You might experiment with the following code to clean up your files.
This will remove all the existing lines and replace them with whatever is in $line3 and $line4.
Be sure to do a backup before starting.
I got the above to work and it works correctly even when I change the values for $line3 and $line4
question? if I put the printf statement inside the if fi clause it gets bypassed completely and how do I pass variables $line1 and $line2 to sed?
Thanks for explaining the $f to me it help a lot to know where to put echo commands so I could see what was going on.
I am going to run it on a copy of my real directory tree via virtualbox see how it goes.
How to get a file 'zlib.h' in an entire directory with an excluded directory specified lives under that starting directory by using find command, as it failed on:
$ find . -name 'zlib.h' -a -ipath 'CHROME.TMP' -prune -o -print
it'll just list entirely up (2 Replies)
I am new to Perl. I wrote a Perl program that inserts text "EnableScrollableCursors=3" after a section of contexts in the odbc.ini file matches a variable in an array list. "EnableScrollableCursors=3" is added to a newline before whitespaces separate each section of contexts in the odbc.ini.
... (0 Replies)
Hi,
I want to append "chr" to all col 2 values of all files in a particular folder.
This is what I came up with but isnt working. Please help.
ls -1 * |
(
while read line
do
awk 'BEGIN {FS=OFS=":"} {$2="chr"$2;print $0}' $line > $line_new
done
)
Another question is, how to delete... (7 Replies)
Hi,
I have installed ubuntu server lamp.
When I used the command locate to find the php.ini file I found two location.
/etc/php5/cli/php.ini
/etc/php5/apache2/php.ini
When I want to change the setting of the php, which one of them should I change and why I have this file twice? (3 Replies)
Hello,
I have 50 text files in a directory called "AllFiles"
I want to make a program that will go inside of the "AllFiles" Directory and count the number of lines in each individual text file. Then, the program will calculate how many more lines there are over 400 in each text file and... (7 Replies)
Hi,
I've spent some time researching for this but can't seem to find a solution. I have a file like this
1234|Test|20101111|18:00|19:00There will be multiple lines in the file with the same kind of format. For every line I need to make it this
1234|Test|20101111|18:00|19:00||create... (5 Replies)
I have a working directory on a server with over 100 INI files. For the most part, they are configured the same way. Each line will contain 1 or none variables listed from the first character in the line such as VariableName=0.
Unfortunately there are comments everywhere using the... (4 Replies)
I can't use mysql .How should i config the file of php.ini . the message:
Fatal error: Call to undefined function mysql_errno() in /var/www/html/inc/dv_clssql.php on line 129
how should i do? please help me (2 Replies)
Is this possible? Let me know If I need specify further on what I am trying to do- I just want to spare you the boring details of my personal file management.
Thanks in advance-
Brian- (2 Replies)