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.
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.
Continue reading Perl : Optimizing pattern searches with Regexp::Assemble
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.
Continue reading Linux : Taking control of Virtual Terminals (VT) from command line
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.
Script started, file is typescript
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)
To replace a text in a file, you can invoke sed as in the following example :
% 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 :
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 ðŸ™‚
If you want to know on which CD is a package, without :
- Mounting CD
- Swear and
- Go back to 1
Then you can :
- Mount CD #1 (mount -F hsfs /dev/dsk/<CDROM DEVICE> /mnt or, if you have automount cd /cdrom/cdrom0 or something like that)
- Go in the Solaris_10/Product directory of the CD
- Do grep -l <PACKAGE NAME> .virtual_packagetoc_*
which will output the .virtual_packagetoc_N where N is the number of the CD holding that package.
# grep -l SUNWzsh .virtual_packagetoc_*
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 !)
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).
Continue reading CFEngine – Installing on Debian GNU/Linux
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.
Continue reading CFEngine – What is it ?
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.
Continue reading Keeping track of changes with cfengine and SubVersioN
not to me !! ðŸ˜€
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