/etc insider

since 1999 (and still editing)

Prefer fgrep instead of grep

| Comments

People tend to get used to something and then the habbits rule them. You’re probably a heavy grep user, aren’t you? You can find grep in lots of one-liners, code snippets and so on. But do you really typically need its ability to search with regular expressions? Not that often I can assume. Meanwhile fgrep is just typically faster, so when you’re greping through some heavy log-file you’re wasting time and CPU cycles. Time is more important, usually. Say you want to find a string which includes dots, but not in the meaning of “any character”, just dot. Let’s see:

1
2
try# time grep no.ImSure.Theres.NoSuch.AString.Inside huge.log
grep no.ImSure.Theres.NoSuch.AString.Inside huge.log  1.05s user 0.27s system 99% cpu 1.333 total

Now let’s try fgrep:

1
2
try# time fgrep no.ImSure.Theres.NoSuch.AString.Inside huge.log
fgrep no.ImSure.Theres.NoSuch.AString.Inside huge.log  0.35s user 0.23s system 99% cpu 0.590 total

– whoa. Two times faster! What if you decided to be fair with grep and told it the dots are just dots, not “any char”(?):

1
2
try# time grep no\.ImSure\.Theres\.NoSuch\.AString\.Inside huge.log                                                                                                                            
grep no\.ImSure\.Theres\.NoSuch\.AString\.Inside huge.log  1.04s user 0.25s system 99% cpu 1.302 total

– it’s still slow. And once again let’s run fgrep just to memorize that if you don’t need regular expression search then you shoud use proper tool for it – fgrep and you should expect your CPU to be used more effectively, saving your time:

1
2
try# time fgrep no.ImSure.Theres.NoSuch.AString.Inside huge.log                                                                                                                                
fgrep no.ImSure.Theres.NoSuch.AString.Inside huge.log  0.33s user 0.26s system 99% cpu 0.597 total

P.S. It’s quite obvious, but still may be forgotten that grep for an IP-addess with un-escaped dots is asking for trouble cause 10.1.2.3 would match 10.192.34.56 too. fgrep would do better but not ideal to – it’s false-hit area is narrow but still not zero-wide: 110.1.2.33 is an example.

Uncluttering df

| Comments

Typically, on a busy server with a bunch of OpenVZ or possibly LXC containers run, df output is cluttered with lots of tmpfs, devtmpfs and/or simfs entries:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
none                      tmpfs     410M  1.1M  409M   1% /var/lib/vz/root/1060/run
none                      tmpfs     5.0M     0  5.0M   0% /var/lib/vz/root/1060/run/lock
none                      tmpfs     2.0G     0  2.0G   0% /var/lib/vz/root/1060/run/shm
none                      tmpfs     100M     0  100M   0% /var/lib/vz/root/1060/run/user
none                      tmpfs     4.0K     0  4.0K   0% /var/lib/vz/root/12020/sys/fs/cgroup
none                      tmpfs     1.0G     0  1.0G   0% /var/lib/vz/root/12020/tmp
none                      tmpfs     410M  1.1M  409M   1% /var/lib/vz/root/12020/run
none                      tmpfs     5.0M     0  5.0M   0% /var/lib/vz/root/12020/run/lock
none                      tmpfs     2.0G     0  2.0G   0% /var/lib/vz/root/12020/run/shm
none                      tmpfs     100M     0  100M   0% /var/lib/vz/root/12020/run/user
none                      tmpfs     4.0K     0  4.0K   0% /var/lib/vz/root/10800/sys/fs/cgroup
none                      tmpfs     1.0G     0  1.0G   0% /var/lib/vz/root/10800/tmp
none                      tmpfs     308M  1.1M  307M   1% /var/lib/vz/root/10800/run
none                      tmpfs     5.0M     0  5.0M   0% /var/lib/vz/root/10800/run/lock
none                      tmpfs     1.5G     0  1.5G   0% /var/lib/vz/root/10800/run/shm
none                      tmpfs     100M     0  100M   0% /var/lib/vz/root/10800/run/user
none                      tmpfs     4.0G     0  4.0G   0% /var/lib/vz/root/1040/dev/shm

– of course one can use grep (or, better fgrep) to filter out that entries, but df itself has own filtering capabilites allowing to exclude unneeded filesystems. Plus shell (both bash and zsh) allows for shortening such a command with the brace expansion. As a result, you may have something simple and concise as this:

df -Th -x{{dev,}tmp,sim}fs

Not an easy oneliner to memorize, so actually would be best recalled with Ctrl_R it when needed.

So, fuck you Enom!

| Comments

Written – as promised in Twitter. Was very surprised to have found out that the site’s “not available” due to those assholes decided to revoke the domain delegation and even blocked my account without sending out any fucking notice to me! If you can’t login and see “account status doesn’t permit this action - 7” – very likely this is exactly what has happened.

When I called them on phone, a “supporter” told me I should send a mail to “risk management at Enom”. I decided I should just have sent Enom a kiss-my-ass goodbye instead. Seriosly, I don’t think those jerks should be treated any better.

N.B. Keep it in mind: if you ever need to register a domain avoid dealing with Enom – they have no respect to theirs customers. Enom can literally wipe out your domain without any prior warning. Anyone can just go and re-register your domain while Enom’s doing it. And Enom just don’t give a shit. Absolutely.

What time zone does localtime define?

| Comments

Someday you wake up having a hangover headache, issue date to locate yourself in time and realize you have no idea where did /etc/localtime come from? This oneliner can help:

1
2
find /usr/share/zoneinfo -type f | xargs -r md5sum | fgrep `md5sum /etc/localtime|cut -d' ' -f1`
e4ca381035a34b7a852184cc0dd89baa  /usr/share/zoneinfo/posixrules

of course /etc/localtime happens to be a symlink sometimes, but this is too trivial even for hangover.

Forgotten sudo vim workaround

| Comments

Preferring to use sudo instead of using root account all the time, sometimes I find myself in the middle of vim-session run w/o super-user privileges. I guess this is something not too uncommon so here’s how not to have a romp with all those saving into temproary file then substituting the original with it – do substition in vim itself:

:%!sudo tee %

tune2fs if busybox df shows no inodes

| Comments

In a gory case of your busybox df “applet” doesn’t have a notion of -i and you still wonder how many inodes occupied/free you can try checking if you’re lucky enough to have tune2fs installed – dumping its output through fgrep -i node you should have your curiosity fully satisfied:

1
2
3
4
5
6
7
8
Inode count:              1441792
Free inodes:              1115832
Inodes per group:         8192
Inode blocks per group:   512
First inode:              11
Inode size:               256
Journal inode:            8
Journal backup:           inode blocks

UltraKSM makes Chrome half mem use

| Comments

Small proof that UltraKSM’s really worth applying its patch to your Linux kernel: – Yeah, that’s correct – in ~ 10 minutes RSS goes down to 970 MB instead of 1.849 GB.

I’m not sure about increased CPU usage (twice as well), but even if it’s related to memory “compaction” it’s an even trade, as to me.

P.S. I bet it’s something your Mac still can’t do, isn’t it? ;-P

Using Octopress

| Comments

Ok!

Actually it wasn’t just following instructions to get Octopress up and running! It made me to figure out first that I need to install OpenSSL, zlib (actually GCC and Make too, but this is something you should expect when it comes to building software). It also required re-compiling ruby install every time I founded out another one dependency needed and some ruby dependent command still not working. But yeah, not a rocket since at all and now it looks like I really can start blogging all what I want about. ;)

But hey, it’s gonna take you to study markdown as well. :)

What I don’t feel like okay:

  • Using date in posts URL might seem like a good idea, but hey, what if you want to change date meanwhile having some links to the post in question already? Tinkering with “mod_rewrite”? An unique ID preceeding the date could better suite (or, probably there’s no need in date in URL at all).
  • Source files (postings) are a mess-in-one-directory – can you imagine what would be there after a few years of active blogging?
  • Images handling – where to upload (properly)? I mean even source posting files are mess but at least they’re told “to be there”, images are completely on your own.