Articles about bash

Baby Tux

This handy script will allow you to get the current Load Average (loadavg) for a remote server over SSH. It will stream the result set back to you, which you can then pipe into a file if you need to.

This would be handy for monitoring the load of a server while stress testing, for example.

After Worldpay recently changed to use the RBS system, I was tasked with finding every instance of select.worldpay.com/wcc/purchase in our forms and replacing it with select.wp3.rbsworldpay.com/wcc/purchase. There appeared to be thousands of files and I wasn't going to do it manually…

Back in November last year, I wrote a script which handled backing up a drupal database. There were quite a few comments and I've taken some on board and developed the script on a little further to be more "generic".

One of the main complaints/suggestions about my previous snippet was the hard coded nature of it. The follow script offers far more configuration through the command line itself.

I just needed to find the largest files in a folder (in an attempt to find out why it was so bloody huge!) and have ended up with the following handy combination of commands…

find /path/to/folder -size +1M -print0 | xargs -0 du -h | sort -nr

I was just dumping a database using mysqldump and I noticed that tables such as cache (and its cousins cache_page, cache_menu, etc), sessions and watchdog can be pretty big and are also not often essential for backing up. I mean, when you restore your web site do you really care about restoring people's logged in sessions from when the backup took place? I can understand maybe keeping watchdog; but then again should you lose your site you would probably lose it several hours after the backup so would miss out on any relevant watchdog notices.

Anywho… I did a mysqdump for a large database for a website I maintain and the dump came out at 400Mb. I then spent a few minutes cobling together a small script which would do a mysqldump but had some pre-programmed Regular Expressions to match specific groups of tables which it would only dump the structure for (ie, no data). After running this script, the SQL dump was only 220Mb. Much better! It also runs considerable quicker too and will cause less table locking.

So - the script?

Lighttpd Logo

Following my previous post about configuring Lighttpd on this VPS Webserver to replace Apache I bring you a guide to configuring AWStats under Lighttpd. This process is differs to Apache as control of directories and aliasing is handled differently. There can also be complications if you have previously enabled the Drupal LUA Magnet script on your site for clean URL handling!

This afternoon I needed to rename a bunch of files from one form to another in a command shell… Well technically I didn't need to do it in a shell - but, as sure as there is a hole in my ass, I wasn't gonna go through renaming them all manually!

They needed to go from, for example, add.png to add_32.png. After a little research into commands like printf, awk, bison and so on - I suddenly realized that 'cut' held the key!

Subscribe to Articles about bash