crontab -e: I can’t use the default editor!

Usually we use crontab -e command, while logged in as a user, to modify the user’s cron jobs or crontab -e -u[user] as root.

The editor used fot this depends on the system variable VISUAL or EDITOR (if present) else the default editor will be used /usr/bin/editor.

So if the default editor is a not well known program (take “VI” as an example, even if you use the more user friendly “VIM”…), you can modify the suggested system variables if present, to verify:

set | grep -iE ‘(visual)|(editor)’

grep, cut, awk, sort, uniq… linux shell power!

How powerful can be linux shell? This is just an other nice example of the power of linux shell!

Well, this is the game: suppose to need on a remote machine to count how many times an ip address (or user or whatever you want) is used in a log file or a part of it.

Let’s take a sample log: Apache access log.

The format is something like (see attached example log file):
1.1.1.1 – – [16/Jan/2008:22:18:42 +0100] “GET /dir/pag.htm” 200 11 “http://diegobelotti.com/a.php” “Mozilla 5 (Windows..) Firefox”

Aggiornamento costante e automatico di data e ora su macchine linux

Il file in allegato è un semplice script bash che corregge data e ora di macchine linux (i percorsi degli eseguibili sono presi da una Debian Etch).

Prerequisiti

  • ntpdate: apt-get install ntpdate
  • ntpd stopped: se sul server c’è un demone ntp attivo, probabilmente questo script è inutile
  • porta 123 (UDP) aperta
  • permessi utente: l’utente che lancia lo script deve avere i permessi di modifica all’orologio di sistema

Keep the time and date of your Linux box always up to date

The attached file is a simple bash script, to correct the date and time of your linux box (binaries paths are relative to a Debian Etch).

Prerequisites

  • ntpdate: apt-get install ntpdate
  • ntpd stopped: if you have a ntp daemon running you don’t need this script
  • port 123 (UDP) opened
  • user permission: the user that run the script must have the permission to set up the clock

What the script does

Debian e MySql 5: dov’è finito il file ‘debian-log- rotate.conf’?

In un’installazione standard su Debian di MySql 4, i log binari vengono eliminati automaticamente. E’ necessario configurare la rotazione dei log con il file /etc/mysql/debian-log-rotate.conf in cui viene indicato il numero di file massimo da tenere.

A partire da MySql 5, la cancellazione dei log binari più vecchi è fatta direttamente da MySql, per cui non c’è più bisogno del file debian-log-rotate.conf ed è possibile configurare la rotazione nel file principale my.cnf attraverso la seguente riga:

Debian and MySql 5: where has ‘debian-log- rotate.conf’ file gone?

In a Debian standard installation of MySql 4, binary logs are purged automatically. The file /etc/mysql/debian-log-rotate.conf is needed to tell logrotate how many log files to keep.

Starting from MySql 5, purging of binary logs is done directly by MySql so there is no more need of debian-log-rotate.conf and the rotation is configured in the my.cnf file with the following entry:

expire_logs_days = 30 # WARNING: Using expire_logs_days without bin_log crashes the server! See README.Debian!

Un semplice trova e sostituisci con perl

Se state cercando un modo semplice di trovare e sostituire stringhe in diversi file di testo (php script, bash script, perl script o semplicemente testi) utilizzando un solo comando, quello che segue potrebbe essere il più semplice:

find . -name ‘[PATTERN]’ |xargs perl -pi -e ‘s/[NEEDLE]/[REPLACESTR]/g’

Ad esempio se siete nella cartella dove abitualmente salvate i vostri script di avviso, che inviano mail al presentarsi di certe condizioni, e volete sostituire il vostro vecchio indirizzo email con il nuovo potete digitare