Useful Linux Commands

Frequent questions from clients hosted on our Linux servers regarding quick ways to acheive common task to manage their servers and the files on them have prompted this post.

Here are a list of useful server commands that can be used for those of you running Linux servers, and also will mostly work on Unix too. Root access maybe needed for some of these commands depending on your setup.

Change owner of files and directories
# chown -R user /dir/you/choose
-R
If a pathname on the command line is the name of a directory, chown changes all the files and subdirectories under that directory to belong to the specified owner (and group, if :group is specified). If chown cannot change some file or subdirectory under the directory, it continues to try to change the other files and subdirectories under the directory, but exits with a non-zero status.

Set permissions of all directorys, not files
find . -type d -exec chmod 777 {} \;

The above command changes permissions of all sub directories under the current directory... and doesn't effect files however. Make sure you cd to your directory first, doing this from / is a bad idea.

Check what processes are eating memory and CPU in Linux or Unix
top

The above command will list the most CPU-intensive processes running on your system in live time, as the processes change so does the information displayed. Newer linux installations also list memory useage on the same screen. You can delay the live updates if its all a bit fast by adding the -d flag.. for example, to delay screen updates by 10 seconds use:
top -d 10

More useful commands coming soon ... If you wish to request a command, please do so.

Magento Gets 40% Faster to Load

As boasted by Varien, Magento absolutely is a "platform for growth" however if like us you have been continually disappointed with the performance on a speed point of view from Magento 1.2 then there is good news. On March the 30th 2009 Magento announced the release of 1.3 and claimed that they have improved performance by 40% in both page loading time and memory usage. Keen to see this for our selfs, we loaded a fresh 1.3 installation with around 1,200 products yesterday and at first glance the catalog pages are much faster to load than in 1.2.

Additionally in 1.3 there is the option to use a 'flat' category type for databases of under 1,000 products which should improve performance again for smaller stores.

Magento 1.3 is still not lightening speed, though 1.3 is still quite a young release. Magento is certainly still a fantastic product and one to watch for the future.

Magento to Business-Post Integration

We are pleased to announce that we now offer Magento to Business-Post (aka UKMail) integration to allow orders placed in Magento to be sent directly to Business-Post through their customer gateway software, Consignor Despatch System.

Basic integration is available for £150 plus VAT. Please call us on 0845 459 1053 for more information or send us an email from here.

Saving Form Data Twice in CakePHP

CakePHP makes it increbibly easy to insert data into MySQL tables with the use of their inbuilt form helper and and save function however one question I have seen alot is how to save form data more than once equating to multiple row inserts? The answer is actually quite simple.

When you use the CakePHP save method, CakePHP holds on to the last primary ID it created, and so if you try using the save method again, in the same session.. nothing happens, as the row already exists as far as Cake is concerned. You need to make Cake forget about the last primary ID it's holding.


$this->Whatever->create();
$this->Whatever->save($this->data);

$this->Whatever->create();
$this->Whatever->save($this->data);

The code above runs the create() method on the Whatever model reseting any primary ID Cake was holding for it. Then it runs the save method saving the form data to the Whatever model. It then runs the create method again, resetting the primary ID and then saves the form data again, giving you two rows in your table with the same data all bar the primary key.

Of course you would more than likely put your save in a loop of some kind if you were planning on multiple saves.


$inserts_required = 1;
while ($inserts_required <= 10) {

$this->Whatever->create();
$this->Whatever->save($this->data));
echo $inserts_required++;
}

The above will insert 10 rows with the same data, bar the primary ID.

Spam Sending Clients on Shared Cpanel Servers

Recently one of our reseller Cpanel clients on one of our shared servers managed to have the shared server IP blacklisted in two popular blacklists by sending out spam email using an automated mailing script. As you may know, when one client gets a shared IP blacklisted all clients on that IP are then effected so this was a priority case for us.

Believe it or not many of the most popular blacklists such as SpamCOP are more than happy to remove an IP as a spam source providing you can prove you are not a spam trader. Some of the blacklists you must manually request an IP to be removed however others will automatically remove an IP if it does not get any complaints or trap any spam from it within a number of hours.

Tips to Recover from your Shared Cpanel Server Blacklisting

  1. Of course the first step was to remove the offending auto mailing script and shutdown the said client's hosting account. Done.
  2. Next, search the blacklists for your shared IP. There are some good free tools out there to help you with this. Such as MX Toolbox.
  3. Contact each blacklist your IP appears in and advise you have taken steps to remove your offending client and increase mail security. Await further instruction from each blacklist.

On Spam Prevention using WHM
As the shared IP in question here belonged to a WHM server we run, we will cover some WHM settings that could go a long way in the fight against clients who like to spam.

Load up WHM as root and click through to Main >> Server Configuration >> Tweak Settings and scroll down to mail. There are two very useful settings here.

The maximum each domain can send out per hour

This is quite self explanatory, set it to a low number rather than the default of 0 which is unlimited and each domain is seriously halted when it comes to sending bulk mails.

Prevent the user "nobody" from sending out mail to remote addresses

Some poorer auto mailing scripts will send mail out as the user nobody, set this setting to enabled and this decreases the risk too.

We hope these notes can be of use to individuals and companies alike in the ongoing fight against spam.