All posts tagged script

Memory leaks caused by PHP are hard to pinpoint. My server started crashing regularly, out of memory from running WordPress on Apache22 and FreeBSD. It happens especially when posting, but also at random times. I tried disabling plugins, changing the theme, to no avail. There might be more than one faulty script, and there is little hope to find these leaks. Hopefully they will be plugged in future releases. In the mean time, I wrote a Python script that checks memory status and restarts Apache if needed. Placed on a cron job, it runs every ten minutes on my server.:

It is a temporary fix, but it works. Her is my /etc/crontab line:
*/0 * * * * root /usr/local/bin/python /home/gil/scripts/

Good luck!

It doesn’t take more than one directory on your web server with write permissions to let someone in.. I started to notice Perl processes running under the www user on my server. It was taking a lot of the CPU, and I couldn’t find the culprit. The only thing I could do was shutting down the Apache web server, then killing the www processes: kill -9 -uwww. But then, it would restart later. So, I looked in the most likely directory /tmp for suspicious files. There were… Perl scripts disguised as images or txt files. It was an Indonesian IRC bot. I removed the files, wondering how they got into /tmp.

The next day, the offending processes resumed! There had to be some other malicious Perl script somewhere. I did a grep -R /usr/bin/perl /home. To locate all files chmoded 777, I tried find /home -type d -perm 777. One of my users was running OSCommerce, and had the images directory chmoded to 777. Ha! The directory was full of exploit files owned by the www user. I deleted them and chmoded the directory to 755. Hopefully that will be the end of it. I will keep a close eye on server processes and any new files owned by www, or containing Perl code.

Any suggestion would be appreciated on how to avoid future problems. I strongly encourage anyone managing a server to check their permissions, and look for Perl scripts that shouldn’t be there.

I just discovered the Pretty Link WordPress plugin, and I think it will help getting more returning visitors to my site, especially using the Pretty Bar feature. Problem is, I have 11,000 posts, with almost as many links. So, I wrote a Python Script to convert all your old post links to Pretty Links. You need to insert your database login on lines 23,24,25,26. Replace ‘planenews’ on line 49 by your site name, without the .com. Replace my domain by yours on line 58. If you leave line 69 as it, the script will set your Pretty Links to show with the Pretty Bar, standard parameter forwarding, group 1, traking on. If it works for you, you better send me a few bucks to buy a Cigar or a Cointreau, because this will save you a lot of time! (Click on the Donate button below), Scroll down to get the code…

Update: You may have to run it a few times until the script returns no result.. No time to figure out why.. Make sure you backup your database before playing with this!

I had problems with the Google XML sitemap generator plugin because of my database size, more than 10,000 articles. Here is a Python script that will work no matter how large your database is. Make sure you edit the domain name at the end, for the home page entry, path to the sitemap.xml file, and of course, put in your database login info. Put the script on a cron-job, et voila! See the code below…

Here is a script to convert you PHP-Nuke database to your new WordPress one. It does not transfer comments, but does users, topics and stories. It is written in Python. You need to edit the database logins and specify your url and PHPNuke admin user id. The MySQLdb Python module must be installed. If it works for you, you better send me a few bucks to buy a Cigar or a Cointreau, because this will save you a lot of time! (Click on the Donate button below), Scroll down to get the code…

And by the way, here are the two lines to put in your .htacesss file to convert the old PHPNuke URLs to the new WordPress numeric urls. The will turn, for example:


So your visitors coming from an old link won’t miss a beat.. Here it is:

RewriteCond %{QUERY_STRING} ^name=News&file=article&sid=([0-9]*)
RewriteRule ^modules.php$ /archives/%1? [R=301,L]