Categories
Tips

Killing Zombie Processes on Linux

You can’t kill zombie processes by sending them “kill -9” directly. Because zombies are already dead!

So its better to kill their “parent” process, unless inits init process.

Run following command…

ps -el | grep Z

Look for PPID

F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
5 Z     0  2756  2755  0  80   0 -     0 exit   ?        00:00:00 php-fpm <defunct>

If PPID is not 1 then you are lucky.

You can kill parent process by running following command:

kill -9 2755

Thats it!

 

 

Categories
Tutorial

Compiling ghostscript 8.71 from sources

In a recent project, where we are working on converting PDF based newspapers to interactive image slideshows, we came across an issue with ghostscript version 9.05. This version was breaking rendering of some Marathi fonts present in PDF.

When tested on ghostscript version 8.71, conversion was working properly. So we decided to downgrade ghostscript from version 9.05 to 8.71 on our server running Ubuntu 12.04 LS. Below are steps we followed.

Compiling ghostscript 8.71 from sources

Download sources from http://downloads.ghostscript.com/public/

ADVERTISEMENT
wget http://downloads.ghostscript.com/public/ghostscript-8.71.tar.gz

Uncompress downloaded source code & change to directory.

tar xvf ghostscript-8.71.tar.gz
cd ghostscript-8.71
ADVERTISEMENT

Configure it (I used all defaults)

./configure

Start compilation with

make

If you encounter following error:

ADVERTISEMENT
./base/gp_unix.c:148:2: warning: implicit declaration of function ‘gettimeofday’ [-Wimplicit-function-declaration]
make: *** [obj/gp_unix.o] Error 1

Compile using

make XCFLAGS=-DHAVE_SYS_TIME_H=1

Finally install compiled binaries using

make install
ADVERTISEMENT

At this point you will ghostscript will be installed at /usr/local/bin/gs

There are other methods to install old versions also, but compilation is safer alternative IMHO.

About the project:

rtCamp is working on an exciting project to connect WordPress with conventional newspaper publishing. The project is in early stages and a sample can be seen at http://anandnagri.com/e-paper/22-aug-2012-3/ (Note: you may see some text in images broken if you visit this on Aug 24 or Aug 25 as all images are recreated using ghostscript 8.71 right now)

 

Categories
Tutorial

Using grep to removing comments, newlines/whitespace from config files

As configuration files are often full with comments and blank lines reading them inside shell become tedious! Sometimes you just want to quickly recap active configuration option only.

Mostly, comments starts with “#“(hash) or “;” (semicolon).

Below is a command I often use while debugging various configuration files.

For files having comment starting with “;” e.g. php.ini

egrep -v "^([[:space:]]?$|;)" /path/to/file

For files having comment starting with “#” e.g. my.cnf

egrep -v "^([[:space:]]?$|#)" /path/to/file

For lazy bumps… Following can take care of both of above! 

egrep -v "^([[:space:]]?$|;|#)" /path/to/file

You may create a local alias for above command! 😉

Just in case you want to save output in a file… just add " > newfilename" to above commands. Passing original filename may not work (and it will be risky too!)

Categories
Tips

Fix File Permission on Linux/Mac Server

Over the time, file permissions get messy on a linux/mac server. It really annoys (me) to see static files like images have 0755 i.e. executable permission set for them.

You can use following commands to fix permissions:

find . -type d -print0 | xargs -0 chmod 0775
find . -type f -print0 | xargs -0 chmod 0664

I found many scripts and tools to do this job. IMHO, above command does what we really need!

For WordPress

Ideally, on a wordpress site, no files under “wp-content/uploads” directory should be executable. In case of WordPress multisite, it will be “wp-content/blogs.dir” directory.

Its better to fix file-permissions periodically on your WordPress setup.

Categories
Tutorial

Ubuntu Server + CrashPlan + Backup + Remote Management using Mac

We already use rsanpshot for backups. But its always feel safe to have more than one kind of backup.

For other type of backup, we use Crashplan. They support all major platforms, provides many options and have their service decently priced. It will take a separate post to list down all things I like about Crashplan so lets get back to work here!

What I wanted to do:

  1. Run Crashplan on Ubuntu Headless Server.
  2. Manage it using Crashplan desktop software on my Mac.
ADVERTISEMENT
I guess you can start remote X session or something like that on a Ubuntu server but that will be overkill for server. Specially when you can achieve above tasks in just 2 minutes using following commands.

Preparation

Crashplan on Ubuntu will need Java Runtime (JRE). Crashplan can install it itself but I prefer to have more control over which JRE I end up putting on our server. They have almost 5 version of JAVA for Ubuntu!

Anyway, just run following command as root user or with sudo access:

ADVERTISEMENT
apt-get install openjdk-7-jre-headless

Install Crashplan

Next, we will install Crashplan directly.

Go to Crashplan site, select Linux version and copy-download link to grab latest Crashplan version. Crashplan 3.2.1 is latest as of July 2012.

Run following commands to download, uncompress and install CrashPlan or CrashPlan+

ADVERTISEMENT
wget http://download.crashplan.com/installs/linux/install/CrashPlan/CrashPlan_3.2.1_Linux.tgz
tar -zxvf CrashPlan_3.2.1_Linux.tgz
cd CrashPlan-install
./install.sh

If you are using CrashPlan PRO, use following…

wget http://download.crashplan.com/installs/linux/install/CrashPlanPRO/CrashPlanPRO_3.5.3_Linux.tgz
tar -zxvf CrashPlanPRO_3.5.3_Linux.tgz
cd CrashPlanPRO-install
./install.sh

Installer will ask you for many questions. Just keep hitting enter keys. Defaults options are all good to go ahead!

At this point Crashplan is running on your Ubuntu Server but it’s not backing anything yet! We will use Crashplan’s Desktop edition for Mac to start backup.

ADVERTISEMENT

Troubleshooting

If your installation ends with warning:

Your Linux system is currently configured to watch 8192 files in real time.
We recommend using a larger value; see the CrashPlan support site for details

Then you need to tweak sysctl file:

/etc/sysctl.d/custom.conf
ADVERTISEMENT

Add…

fs.inotify.max_user_watches=1048576

Save changes…

sysctl -p

Remote Management UI (using Mac)

Go to Crashplan’s site. This time download Crashplan for Mac & Install it.

If you have started Crashplan after installation, quit it.

Open terminal to edit Crashplan config file…

vim /Applications/CrashPlan.app/Contents/Resources/Java/conf/ui.properties

You can use any text-editor in case you don’e like Vim.

Find a line like below:

#servicePort=4243

Change it to:

servicePort=4200

Note that we have changed port number from 4243 to 4200 (in case you thought we just uncomment it!).

Save file. Exit vim.

Create SSH Tunnel from your mac to remote Ubuntu server using a command-like below:

ssh -L 4200:localhost:4243 username@hostname

Replace username and hostname with your a real username on your hostname. You can put your server IP address also.

After you run above command, you will be logged into a shell on your server. Keep it running as its connecting your desktop crashplan to your server crashplan!

Finally, you can start your Crashplan on Mac and configure backup for your Ubuntu Server!

In case you are already using Crashplan to manage your Mac’s local backup:

  • You will need to exit from shell (to break connection)
  • comment-out “servicePort” line in Crashplan config
  • Restrat Crashplan so it will work with Mac’s local config

There is no easy-way to switch between local & remote machines. (Atleast at the time of writing this…)

Categories
Tutorial

Remove “eval(base64_decode” using linux commands from all php files across multiple WordPress

Yesterday, almost all installations on our test server had been infected by infamous “<?php eval(base64_decode(…)) ?>” code injection.

We have more than 600 demo sites on our test server and cleaning them using any WordPress plugin out there was simply out of the question! Can you imagine logging into each WordPress, installing plugin, then scanning/cleaning up WordPress… for 600+ WordPress sites?

Below is combination of Linux commands we used.  Assuming you have logged into a Linux Shell and already have BACKUP of all files (including infected files) lets move ahead!

Command to list all infected files:

ADVERTISEMENT

grep -lr --include=*.php "eval(base64_decode" /path/to/webroot

This is not necessary but its better to check some files manually to confirm if they have malicious code we are looking for. Also we can use this command after running cleanup command to crosscheck if cleanup is really successful.

Command to remove malicious code:

If above command gives you correct output, execute following command to perform actual cleaning:

ADVERTISEMENT

grep -lr --include=*.php "eval(base64_decode" /path/to/webroot | xargs sed -i.bak 's/<?php eval(base64_decode[^;]*;/<?phpn/g'

Executing above will remove eval(*) codes.  Above command will also generate a backup version of files it will modify. For example, if it removes code from index.php, you will find a new file index.php.bak in same directory with original content of index.php

Now after running above command, you still find some more infected files, then you need to adjust search and replace parameters in for “sed” part.    You may also use following command for a “liberal” cleaning at the risk of breaking something. (in case you really break something, like I did, you can jump to “Troubleshooting” section below!)

grep -lr --include=*.php "eval(base64_decode" /path/to/webroot | xargs sed -i.bak '/eval(base64_decode*/d'

Trying to avoid re-appearance of this code injection

ADVERTISEMENT

Its really though to cover every possible way to protect yourself from such attach in this post.

If you remember, WordPress community faced this kind of issue because of WP-PhpMyAdmin plugin sometime back. In our case, we found some old WordPress demo sites were having that plugin installed.

To remove WP-PhpMyAdmin plugin form all WordPress sites on your server, execute following command:

find /path/to/webroot -name "wp-phpmyadmin" -type d | xargs rm -rf

Above is all we did to get rid of eval(base64_decode(*)) codes from all files on our test server. If this happens again on our server, I will update this post with added info.

ADVERTISEMENT

Troubleshooting:

Just in case you end up in a mess, below are some useful commands.

Missing <?php tag in the beginning:

To add “<?php: tag in the beginning of index.php files, in case if you remove it accidentally use following command:

find /var/www/ -name "index.php" | grep "/htdocs/index.php" | xargs grep -L "<?php" | xargs sed -i "1s/^/<?php n/"

Don’t worry. If you already have a “<?php ” tag in the beginning, it won’t be added again.

Extra Newlines at the top!

If you find after cleanup, extra newlines at the top of your code, then use following command to remove trailing newlines. Extra newlines creates problem for blog feeds.

find . -name '*.php' -exec sed -i -e :a -e '/^n*$/{$d;N;ba' -e '}' '{}' ;

I hope you will find this stuff useful.

Categories
Tips

Automatically Store Photos From Your Camera to Dropbox [Desktop]

Dropbox is ramping up its service in a big way over the past few days. For starters it has a new design for it’s website. It also has introduced photo-storing features from mobile phones and PCs. These new options by Dropbox are very important as soon it will face competition from Google and Microsoft with their own cloud storage and sync services.

Considering a lot of photos are taken from mobile phones, this could a make or break feature for Dropbox. It helps that Dropbox is not part of a larger company, which allows a lot of third-party apps to work with it. For example you can read how I use Dropbox to automatically store images from my Facebook account.

Dropbox (Beta) on Desktops for Connected Devices

  • Download the latest beta version of Dropbox and install it.
  • Connect your digital camera or mobile phone which has your photos. The connected device can be opened on Auto-Play using Dropbox. So make sure on your Windows computer, Auto-play option is not disabled.

  • Click on the Dropbox option and all the photos from your camera are transferred onto a folder on dropbox.

  • This folder is usually named “Camera Uploads”. Once you update your photos, you will get 3GB additional space.

Saving Photos from your Android phone to Dropbox

If you have a Android phone, then download the Dropbox App on it. This will automatically sync your photos from your phone onto your Dropbox account.

Mac and Linux users can also avail of the latest beta build from the forum link below, to photo-storing is enabled on their computers too.

Direct Download Link: Dropbox Beta (Windows) | Dropbox (Android)

Link: Dropbox Experimental Build Forum

Categories
Tips

Search and Find Games for Linux Online

Most open-sourced Operating Systems are designed on the Linux kernel. Linux stands shoulder to shoulder with Windows when it comes to performance and User Interface. But it loses out when it comes to software compatibility.

Many such issues are solved by using open source alternatives which are not as good as the paid ones. Hence when it comes to gaming, everyone prefers Windows as it supports a lot of games.

Also, another drawback is we do not find a lot of games that run on Linux. 🙁

Penguspy is a website that really good for looking up free Linux based games online.

Penguspy Features

  • The site is very useful if you are predominantly a Linux user and feel the need to have Windows only for gaming needs.
  • The games are classified into several categories like arcade, action, adventure, puzzle, FPS, RPG, sim, sport etc.
  • You just want to select a category, select the game and you can see it’s trailer, ratings, some reviews and a link to download them.

If you are using Linux, try out Penguspy and do drop in your comments.

Link: Penguspy

Categories
Tips

[How To] Create a Live USB of your Favorite Linux Distro

Well, after enjoying the power of Windows 7, I decided to go back to some of my favorite Linux flavors. I like testing out different flavors of Linux and my favorite is Ubuntu. I like it because it’s robust, the community is large enough to provide you with help and the software is easily available.

With the new release of Fedora 14, came many online debates about which one is better- Ubuntu or Fedora? So I decided to try out Fedora.

If you have never tried any Linux, I would recommend you to do so now! Here is a quick tutorial which will help you run or install a linux distro using a Flash/Pen Drive.

ADVERTISEMENT

Things You Need

  1. A good computer with a fast internet connection to download the disk image of the Linux you want to try. Distros are usually 600-700 Mb
  2. A Pen Drive(1GB minimum)
  3. A Brain! (just kidding, it’s as simple as 1-2-3)

NOTE: The USB key will be formatted, so don’t forget to backup the data in the USB you’re going to use.

Install Linux Live USB Creator

There are many ways to make a USB drive bootable, but the simplest way to do so is using a tool called Linux Live USB Creator which will not only make your Flash Drive bootable, but will also help you extract ISO image and make the Flash Drive ready for Linux Installation. Download Linux Live USB Creator from here and open the software

Follow the Steps below:

  1. Choose your Flash Drive/ Pen Drive – If it’s not listed, make sure that your Pen/Flash Drive is connected to your computer and then click on the Refresh button on the side).
  2. Choose a Source – If you’ve downloaded the ISO Image, then click on ISO/IMG/ZIP and browse to select your ISO Image(example- Fedora.ISO). If you have the CD of the Linux Distro then click on CD. If you want to download the distro, then click on Download and choose the Linux Distro you want to download and then choose between Manual and Automatic Download.
  3. Persistence mode is used to store the application, log files, information on the USB so that you don’t have to install applications every time you insert the USB in a new computer. This mode can be used by few of the Linux Distros. If you want to install the Distro in your computer then there is no need to use persistence mode.
  4. If you want to Hide the Linux files on the USB then check on the Hide Created Files on Key Option. Check the Format the key in FAT32 format option. If you want to try the Linux without rebooting your computer, check the third option, this will download some files from it’s server and will run the Linux distro in a Virtual Box.
  5. Click on The lightning icon to start the installation process. Now, LiLi will extract the files from the ISO image and then your USB will be ready to use.
  6. After this, shut down the computer and then start it with USB Key connected to the drive. As soon as the Splash Screen of your motherboard appears, press F2 ( Or the key used to access BIOS settings).
  7. Now, go to BOOT Option and then Enable Boot From USB First or anything similar to this term. After enabling it, Save and Exit from the BIOS and now, you’re done! You will now see the booting screen of your Linux Distro and then run the install (if you want to install), and if you don’t want to install it, then start exploring it using the live mode. After you install, don’t forget to revert back the changes you did with the BIOS.

NOTE: Many Linux Flavors allow you to install the Linux side by side of Windows. If you want to use Ubuntu, then try Wubi. Wubi is a free application which lets you install Ubuntu side by side of Windows without the hassle of booting from a CD or USB Key.

Link: Linux Live USB Creator

Categories
Reviews

JDownloader – All in one download manager for Linux

I have been using Ubuntu for few years and was searching for a feature-rich download manager for years. Recently, I came across the best platform independent, all-in-one open source download manager named JDownloader which has attractive features, which substitutes the popular Internet Download (Manager for Windows) in most of it’s features.

  • Platform independent. (Windows, Linux, Mac, ..)
  • Runs on Java 1.5 or higher
  • Completely Open-Source (GPL)
  • 24-hour support
  • Add-ons
  • Download several files parellel
  • Download with multiple connections
  • JD has an own powerful OCR module (JAntiCaptcha)
  • Decrypt RSDF, CCF and DLC Containerfiles
  • Decryptplugins for many services. e.g. sj.org, UCMS, WordPress, RLSLog….
  • Youtube, Vimeo, clipfish video and Mp3 Download
  • Automatic extractor (including password list search) (Rar archives)
  • Theme Support
  • Multilingual
  • About 110 hoster and over 300 decrypt plug-ins
  • Reconnect with JDLiveHeaderScripts: (1400 router supported)
  • Webupdate
  • Integrated package manager for additional modules (eg. Webinterface, Shutdown)

Installing JDownloaded is pretty simple.

ADVERTISEMENT

Please follow the steps for direct bundle.

Method 1 : Download the file; unzip it and you can start using it as shown in the screenshot below

Method 2: Download the script and make it executable by the following ways

ADVERTISEMENT
  1. Right click “jd.sh” -> Properties -> Permissions (tab) -> check “Allow executing file as program” -> Ok
  2. double click on jd.sh -> Run in Terminal — will download all necessary files and you are done with installation.

For beginners, the former method is pretty simple.

NOTE : JDownloader requires Java Runtime Enviroment (jre/jdk) 1.5 or higher. If possible, you should use the latest Java version.

Please share your views on this downloader let me know if there are any other alternative downloaders which you use.