Archive for the 'Linux' Category

Getting rid of those files

Thursday, March 19th, 2009

I've been doing some maintenance of my server, and wanted to do some spring clearning, deleting all spam files inside users' directories. These files are automatically created by spamassassin software. Also, wanted to get rid of Rails production.log files.

Doing everything manually is no fun, and I have to admit, I completely suck at shell scripting.. But if you never try - you'll never learn, so that's what I came up with.

Calculating their size

First, I wanted to find out how much space exactly files called spam inside all directories inside the /home directory take. That's the command which I came up with ( of course, I first had to cd /home ):

[root@me-ja home]# find * -name spam -type f -exec echo {} \; | xargs du -ks | awk '{total += $1} END {print total}'

2952880

A little explanation. I use 3 commands each piping its output to the next one (and the last outputs everything to standard output which is the screen. (more…)

Want to get notified when a long action on remote server completes?

Sunday, July 20th, 2008

Sometimes you might want to run a long action on a remote server, like dump a few gigs DB, or rsync a few thousands of files between two not very fast computers.

You want to take next action as soon as that long operation completes but don't want to baby sit your servers.

How about getting email notification to your.. say.. iPhone.. when the action completes? It's pretty easy! Have a look!

mysqldump -u user -p mydatabase && echo "Dump finished!" | mail -s "Wake up!" mike@example.com

Once the command mysqldump finishes executing,  you'll get mail with subject "Wake up!" and body "Dump finished!"

You can chain more commands, of course, by adding && between them ( && executes next chained command only if the previous one completed without errors)

Pretty cool to have such a simple but useful trick under your belt, isn't it? :)

Rails mailer's receive and sendmail procmail "Service unavailable" problem

Wednesday, February 13th, 2008

I have migrated all my Ruby on Rails system from Fedora Core 6 to RedHat 4.5 recently, and everything was fine, except for that the feature of blogging by email was broken (got a phone call today about that).

I use standard sendmail/procmail integration feature to receive mail to a designated address,  and then pipe it into Rails Mailer's receive function.

So, it looks like that in my /etc/mail/virtusertable:

m@example.com        examplemobile

this way all email which is coming to m@example.com address will be forwarded to system user called examplemobile.

In order to process the mail further and pipe it into my Rails script, I have the following setup in my /etc/aliases file :

examplemobile: "|/usr/local/bin/ruby /var/www/html/examplesite/current/script/runner -e production 'Mailman.receive STDIN.read'"

This setup worked perfectly on Fedora, but broke under RedHat. What's the problem? I was getting the following errors in my maillog:

Feb 13 11:45:33 appserv1 sendmail[32000]: m1D2jXJw032000: from=<xxxxxx@c.vodafone.ne.jp>, size=397, class=0, nrcpts=1, msgid=<20080213114719020972.1b6f@0016E68C4270>, proto=SMTP, daemon=MTA, relay=mmrts035p01c.softbank.ne.jp [123.108.236.87]
Feb 13 11:45:33 appserv1 smrsh: uid 8: attempt to use "ruby /var/www/html/examplesite/current/script/runner -e production 'Mailman.receive STDIN.read'" (stat failed)
Feb 13 11:45:33 appserv1 sendmail[32001]: m1D2jXJw032000: to="|/usr/local/bin/ruby /var/www/html/examplesite/current/script/runner -e production 'Mailman.receive STDIN.read'", ctladdr=<m@examplesite.com> (8/0), delay=00:00:00, xdelay=00:00:00, mailer=prog, pri=30623, dsn=5.0.0, stat=Service unavailable

The problem turned out to be in sendmail setup under RedHat was more secure than the one I had in Fedora. Specifically, this has to do with smrsh (or Sendmail Restricted Shell) thingy. More info about it here. Basically, sendmail only allows piping to programs which (or aliases to them) are present in /etc/smrsh directory.

Since I only use ruby to pipe to, I have added a symbolic link to it inside the /etc/smrsh directory:

[mike@appserv1 smrsh]$ pwd
/etc/smrsh
[mike@appserv1 smrsh]$ ls -l
lrwxrwxrwx  1 root root 19 Feb 13 11:50 ruby -> /usr/local/bin/ruby

Everything works as it should now, and our mobile-blogging users are supposedly happy again :)

RedHat troubles..

Monday, January 28th, 2008

I've been working on setting up two RedHat-based Dell servers at work today.  We have RedHat 4.5 on both machines, with RedHat subscription on one of them (the other one is for DB serving only with extremely limited access to it, so no need to spend money for updated software or patches)

The problem is that I needed to install and configure the environment for my Ruby on Rails based portal systems hosting. New servers, relatively new OS (there's no RHEL 5 for Japanese users yet :/ ), software subscription allowing to install stuff with a single mouse click (well.. literally, that is). What could possibly go wrong?

Well.. RHEL 4.5 went wrong. I just don't get it WHY the software which is piped to the server thru up2date program is so hopelessly, horribly outdated. Apache is at version 2.0.xx, PHP is stuck at 4.x, ImageMagick is at 3.0x, etc, etc…

And I need Apache 2.2 in order to use load balancing feature, RMagick for Rails doesn't want to work with ImageMagick < 3.6.x, PHP 4 just plain sucks (come on! We're at 5.2x series already! Not stable enough huh?). And of course everything gets installed by randomly spreading files over the disk (well.. that's how RHEL works, but I like to have everything/most stuff inside my precious /usr/local directory)

So I had to  reinstall half of the software which was supposed to work out of the box, installed/updated the other half using RedHat Network, and at the end of the day, when I though I have everything working, and moved one of my sites to test on the new system, I started to get seg faults here and there, and the system went pretty unstable.

So, tomorrow I'll just reinstall the whole OS, leaving most the RedHat-supplied stuff off - and will get a 100% working and controllable system with 100% probability.

What I don't understand is - is it me who just doesn't know how to build stuff on top of pre-built stuff, or is it RedHat's approach to installs, oriented to "average user" sort of system admin? Oh well.. one day of work lost, but lessons were learned :)

Subversion RPMs for RedHat Linux 7.3

Tuesday, January 22nd, 2008

I have no idea why you would need them, but I just spent the best half of day trying to compile Subversion from the source of some ancient RHL 7.3 machine - the operation which usually takes a few minutes, but I was getting errors no matter what. Luckily, I found RPM repository which contained everything I needed to install Subversion of that ancient RedHat machine.Here's the link:http://summersoft.fay.ar.us/pub/subversion/1.1.4/redhat-7.x/bin/