Licence
Creative Commons License

This work by Stephane KATTOOR is licensed under a Creative Commons Attribution 3.0 Unported License.
Feeling like tipping ?
If you find this blog useful, you might consider sending a few bitcoins to support it : 1BTtsC3beGJ6ysd8DhrXjdo6jVw5WD9mvY
RSS
 
RSS Feed
Follow me !
Tech@Sakana on Facebook
Search this site

Newsletter

Get latest posts by email (No spam, only posts):

Enter your email address:

Delivered by FeedBurner

Categories
Monthly archives
May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031  
Perl : Convert time from Epoch to local time - March 6, 2008 by Stephane Kattoor

watch

This little Perl one-liner can get handy when you need to translate “time in seconds since the Epoch” (for example in logs) to local time :
% perl -e 'print scalar(localtime(1202484725)), "\n";'
Fri Feb 8 16:32:05 2008
%

This was pretty useful today when browsing through Nagios event logs, where times are given in seconds from the Epoch.

By the way, the Epoch is defined as 00:00 UTC on January, 1st, 1970.

Perl : Optimizing pattern searches with Regexp::Assemble - December 8, 2007 by Stephane Kattoor

When you perform a pattern matching with multiple “or” (|) clauses, such as /pattern1|pattern2|pattern3/, Perl regexp engine will try to match each of them one after the other in sequence, resulting in poor performance if you have a long list of “or” clauses.

In order to optimize such a pattern matching, you can use the Regexp::Assemble module.

read this entry »

Linux : Taking control of Virtual Terminals (VT) from command line - December 1, 2007 by Stephane Kattoor

When you use Linux in text mode (as opposed to with an X server), you readily have access to multiple Virtual Terminals (aka VT for short) by hitting one of your <Alt-Fn> keys (if you are running a X server, you’ll need to hit <Ctrl-Alt-Fn> simultaneously).

This lets you access one of the VTs which are initialized at boot time, but won’t let you create new ones even if your kernel configuration would allow more VTs. Furthermore, what if you want to deal with VTs from a script ?

This post covers the 3 commands which will let you control your VTs from the command line or from a script.

read this entry »

Unix : the “script” command - November 29, 2007 by Stephane Kattoor

The script command is a must for any unix sysadmin.

Once invoked, it will faithfully write anything you typed as well as any output generated in your terminal into a file of your choice (defaults to “typescript”).

This is great when you want to document everything you did on a specific server, for example.
spaghetti:~$ script
Script started, file is typescript
spaghetti:~$

When launched, you don’t see anything, but everything displayed goes to a file as well as the terminal.

As usual see the man page for details (like appending instead of creating a new file, launching another command instead of your default shell, and so on)

sed : replacing a text in a file - October 20, 2007 by Stephane Kattoor

To replace a text in a file, you can invoke sed as in the following example :

1
% cat file.txt | sed -e 's/text/replacement/g' > result.txt

This will change all the occurences of “text” to “replacement” in “file.txt” and output the result in “result.txt”

Note : As suggested by Matthias from adminlife in the comments, if you wanted to do “in place” text replacement (that is modify the file without a temporary file in between), you can do the following :

1
sed -i ’s/text/replacement/g’ file.txt

For more complicated text manipulations you might consider moving to Perl, but sometimes you don’t need the sledge-hammer :-)

Solaris 10: On which CD is that XYZ package ? - August 16, 2007 by Stephane Kattoor

If you want to know on which CD is a package, without :

  1. Mounting CD
  2. Searching
  3. Unmounting
  4. Swear and
  5. Go back to 1

Then you can :

  1. Mount CD #1 (mount -F hsfs /dev/dsk/<CDROM DEVICE> /mnt or, if you have automount cd /cdrom/cdrom0 or something like that)
  2. Go in the Solaris_10/Product directory of the CD
  3. Do grep -l <PACKAGE NAME> .virtual_packagetoc_*
  4. which will output the .virtual_packagetoc_N where N is the number of the CD holding that package.

Exemple :

1
2
3
4
5
# pwd
/mnt/Solaris_10/Product
# grep -l SUNWzsh .virtual_packagetoc_*
.virtual_packagetoc_5
#

So SUNWzsh, the package for ZSH shell, is on CD #5 of Solaris 10 distribution (damn, I don’t have it !)

This tip is courtesy of BlaF (thanks dude !)

CFEngine – Installing on Debian GNU/Linux - April 30, 2007 by Stephane Kattoor

In this post we’ll install CFEngine on a Debian system. Debian make is really simple to install any packages, so let’s follow the “standard” package installation procedure (I’ll assume that apt is correctly setup on your system ! If you have troubles with it, let me know, I’ll write a post on this topic).
read this entry »

CFEngine – What is it ? - April 30, 2007 by Stephane Kattoor

CFEngine is a configuration management engine. I’m going to write a series of short posts as I’m going to use CFEngine in a current project. Let’s start with a short description of CFEngine purpose and main features.
read this entry »

Keeping track of changes with cfengine and SubVersioN - October 13, 2006 by Stephane Kattoor

Cfengine is a tool which purpose is to describe what is a healthy system and how to bring it back to normal when something fails.

I won’t go into an explanation about how cfengine works, because the project webpage already has a neat tutorial and complete reference. Instead of that, I’ll explain how I used cfengine to build a fool proof Linux firewall.

read this entry »

OpenBSD : Give money !! - April 10, 2006 by Stephane Kattoor

not to me !! :D

The OpenBSD project needs money to hold its events (such as hackaton, where developpers gather to implement features, or usual running costs).

If you think you don’t use OpenBSD, think again ! The project OpenSSH, which implements a free, and secure SSH implementation, comes from OpenBSD. It is widely used in many OSes and appliances …

We need OpenBSD !! Don’t hesitate to make a donation !

The original post
The OpenBSD project

The OpenSSH sister project

new entrys »
Who am I ?
Ads