08 06 | 2016

Process command line arguments in shell

Written by Tanguy

Classified in : Homepage, Debian, Command line, To remember

When writing a wrapper script, one often has to process the command line arguments to transform them according to his needs, to change some arguments, to remove or insert some, or perhaps to reorder them.

Read more Process command line arguments in shell

30 10 | 2013

Beware of symlinks when testing a file existence

Written by Tanguy

Classified in : Debian, Command line, To remember

A strange problem

Yesterday, I was reported a funny problem with the dokuwiki Debian package's postinst script, which contains a piece of shell script similar to that:

# Check the destination does not already exist
if [ ! -e /the/destination ]
then
    ln -s /some/file /the/destination
fi

It was failing with that message: ln: failed to create symbolic link '/the/destination': File exists. Even though I had just tested it did not exist!

Read more Beware of symlinks when testing a file existence

06 01 | 2013

GNOME, vous faites ch*er

Written by Tanguy

Classified in : Homepage, Debian-FR, Libre, April, Râlerie

Comme vous le savez peut-être, je maintiens un document d'auto-formation intitulé Formation Debian. Le chantier du moment, c'est donc de la mettre à jour pour la prochaine sortie de Debian Wheezy. Je voudrais donc profiter de ce travail pour énoncer le message suivant : GNOME, vous faites ch*er.

Read more GNOME, vous faites ch*er

05 09 | 2011

Startup scripts of Bash and Zsh

Written by Tanguy

Classified in : Homepage, Debian, Command line, To remember

Both Bash and Zsh use several startup scripts: profile, bashrc, zlogin, zshrc, etc.

The existence of several startup scripts exists to allow you to apply specific actions for interactive or login shells. For instance, you may want to set up a fancy colour prompt or to enable a powerful completion system for interactive shells only, as it would be pointless to apply it to non-interactive shells (that is, for shell scripts). Or you may want to display a joke and the weather forecast at login, but not each time you spawn a shell by other means.

Read more Startup scripts of Bash and Zsh

13 06 | 2011

iptables-restore

Written by Tanguy

Classified in : Homepage, Auto-hébergement, Debian-FR, Libre, April, À retenir

Logo Netfilter (netfilter: firewalling, NAT and packet mangling for Linux)

Utilisation classique d'iptables

iptables(8)/ip6tables(8) est le principal outil de gestion du pare-feu Netfilter de Linux : c'est une commande qui permet en fait de configurer ce pare-feu en modifiant sa liste de règles. Il est le plus souvent utilisé dans des scripts shell qui effectuent une longue succession d'appels pour définir chaque règle :

# Supprimer les règles existantes
ip6tables -f

ip6tables -P INPUT DROP
ip6tables -P OUTPUT ACCEPT

ip6tables -A INPUT -i lo -j ACCEPT
ip6tables -A INPUT -p ipv6-icmp -j ACCEPT

ip6tables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

ip6tables -A INPUT -p tcp --dport ssh -j ACCEPT
ip6tables -A INPUT -p tcp --dports smtp -j ACCEPT
[…]

Cette approche souffre de plusieurs défauts :

  • en appelant de multiple fois la commande ip(6)tables, elle effectue beaucoup de lectures et d'écritures inutiles dans la table de règles de Netfilter ;
  • si une erreur se produit pendant l'exécution du script, le pare-feu se retrouve dans une configuration à moitié appliquée.

Read more iptables-restore

Archives