#!/bin/bash

file=$1 # the input file
directory= »$file-splitted » # the output directory
output= »$directory/header » # the first file containing the header
GREP= »DROP TABLE » # what we are looking for

mkdir $directory # create the output directory

while read line
do
# if the current line contains the wanted statement
if [ $(echo "$line" | grep -c "$GREP") == "1" ]
then
# extract the file name
myfile=$(echo $line | awk ‘{print $5}’ | sed -e ‘s/`//g’ -e ‘s/;//g’)
# set the new file name
output= »$directory/$myfile »
fi
echo « $line » >> $output # write to file
done < $file

coté collectd


Host « localhost »
User « collectd »
Password « Secrets of the Universe with Philo »
Database « mysql »
# MasterStats true

coté Ligne de commande
mysql -u root
mysql> CREATE USER ‘collectd’@’localhost’ IDENTIFIED BY ‘password’;
mysql> GRANT SELECT, PROCESS, SHOW DATABASES, SUPER ON *.* TO ‘collectd’@’localhost’;
mysql> FLUSH PRIVILEGES;

Envoi d’un email + pièce jointeecho "Ci-joint la photo de ma voiture" | mutt -s "Ma voiture" -a voiture.jpg — toto@toto.comLa même chose sans texte d’explication :echo | mutt -s "Ma voiture" -a voiture.jpg — toto@toto.comoumutt -s "Ma voiture" -a voiture.jpg — toto@toto.com < /dev/nullEnvoi d’un email avec plusieurs pièces jointes :echo | mutt -s "Ma voiture" -a voiture.jpg voiture1.jpg — toto@toto.comEnvoyer tous les fichiers jpg par email :echo | mutt -s "Ma voiture" -a .jpg — toto@toto.comEnvoyer tous les fichiers jpg par email avec le contenu d’un fichier texte en corps de message :mutt -s "Ma voiture" -a .jpg — toto@toto.com < mon_message.txt

viaEnvoyer des emails avec piece jointe en ligne de commande sous Linux.

Debian Lenny – nut / Onduleur – Z3 Zenergy 700 VA (INFOSEC)
Publié le Février 23, 2011

Configuration de nut pour l’onduleur Z3 Zenergy 700 – USB de INFOSEC

System : Gnu/Linux Debian 5 – Lenny
kernel : 2.6.26-2-486
Nut : 2.2.2-6.5

Vous avez acquis un onduleur. Malheureusement, celui-ci est partiellement supporté par nut (voir la hardware compatibility list de nut). Bien que l’onduleur soit pourvu d’un port USB, celui-ci est mal détecté par le système Debian Linux Lenny. Le système linux détecte la présence d’un convertisseur USB / Série : Cypress USB to Serial. Son port série virtuel /dev/ttyUSB0 n’étant pas créé automatiquement. Ce port en mode raw est quand même exploitable comme nous allons le voir.

Voyons si les concentrateurs USB détectent la présence de l’onduleur :

# lsusb
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 001 Device 002: ID 0665:5161 Cypress Semiconductor USB to Serial
Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Détaillons les informations USB sur ce périphérique :

#lsusb -v
Bus 001 Device 002: ID 0665:5161 Cypress Semiconductor USB to Serial
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 1.10
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0×0665 Cypress Semiconductor
idProduct 0×5161 USB to Serial
bcdDevice 0.02
iManufacturer 1 INNO TECH
iProduct 2 USB to Serial
iSerial 3 20100813
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 34
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 3 20100813
bmAttributes 0×80
(Bus Powered)
MaxPower 100mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 3 Human Interface Device
bInterfaceSubClass 0 No Subclass
bInterfaceProtocol 0 None
iInterface 4 Sample HID
HID Device Descriptor:
bLength 9
bDescriptorType 33
bcdHID 1.00
bCountryCode 0 Not supported
bNumDescriptors 1
bDescriptorType 34 Report
wDescriptorLength 27
Report Descriptors:
** UNAVAILABLE **
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0×81 EP 1 IN
bmAttributes 3
Transfer Type Interrupt
Synch Type None
Usage Type Data
wMaxPacketSize 0×0008 1x 8 bytes
bInterval 32
Device Status: 0×0000
(Bus Powered)

Malheureusement, aucun port série (virtuel) n’est créé lors de la connection de l’onduleur. Un device standard /dev/hidraw0 sera quand même créé automatiquement pour que le système puisse communiquer en mode directe avec l’onduleur.
Installation de nut

L’installation de nut se fait sans aucun soucis :

#apt-get install nut

Après avoir testé en vain le driver megatec_usb qui aurait dû communiquer avec l’onduleur, j’ai du procéder à l’installation du paquet deb de nut de Debian 6 Squeeze ! Ce paquet (nut_2.4.6.deb minimum) contient le driver blazer_usb utile à nut pour communiquer avec le périphérique.

Disponible sur le site de networkupstools.org, téléchargez le paquet dans la section Download /Binary packages. Un lien vous ramène directement sur la page de téléchargement de nut : http://packages.debian.org/squeeze/nut

Direct link : nut_2.4.3-1.1squeeze1_i386.deb

Installation du paquet :

#dpkg -i nut_2.4.6.deb

Configuration de nut

Fichier : /etc/nut/nut.conf

MODE=standalone
UPSD_OPTIONS=” »
UPSMON_OPTIONS=” »

Fichier : /etc/nut/ups.conf

[Z3_700]
driver = blazer_usb
port = /dev/hidraw0
vendorid = 0665
productid = 5161
desc = “Server Linux Internet”

Ce fichier donne les paramètres associés à votre onduleur. Le nom de l’onduleur, par lequel le système l’identifiera, est indiqué entre les crochets.

Pour les onduleurs en usb, le port = auto pourrait aussi fonctionner. Dans mon cas j’ai dû spécifier le port /dev/hidraw0 créé par le système. Dans l’idéal, un port série virtuel serait disponible pour communiquer avec l’onduleur tel que /dev/ttyS0 ou /dev/ttyUSB0.

Fichier : /etc/nut/upsd.users

[z3]
password = pass_ups
upsmon master

Il s’agit d’un “compte” au sens du service nut.

Fichier : /etc/nut/upsmon.conf

RUN_AS_USER
MONITOR Z3_700@localhost 1 z3 pass_ups master
SHUTDOWNCMD “/sbin/shutdown -h +0″
MINSUPPLIES 1
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 30
DEADTIME 15
POWERDOWNFLAG /etc/killpower
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5

Ce fichier de configuration du moniteur reprend des informations sur l’onduleur du fichier ups.conf

Fichier : /etc/nut/upssched.conf

CMDSCRIPT /upssched-cmd

Une fois tous ces fichiers configurés, vous pouvez tester la communication du driver avec l’onduleur via la commande :

#/lib/nut/blazer_usb -a Z3_700 -DDD -u root

Network UPS Tools – Megatec/Q1 protocol USB driver 0.03 (2.4.3)
0.000000 debug level is ’3′
0.040693 Checking device (0665/5161) (001/002)
0.077674 - VendorID: 0665
0.077760 - ProductID: 5161
0.077776 - Manufacturer: INNO TECH
0.077792 - Product: USB to Serial
0.077807 - Serial Number: *********
0.077822 - Bus: 001
0.077836 Trying to match device
0.078023 Device matches
0.078122 failed to claim USB device: could not claim interface 0: Device or resource busy
0.080628 detached kernel driver from USB device…
0.083726 Trying megatec protocol…
0.087616 send: Q1
1.089450 read: could not claim interface 0: Device or resource busy
1.089548 blazer_status: short reply
1.089570 Status read 1 failed
1.093459 send: Q1
1.151423 read: Q1
1.151487 blazer_status: short reply
1.151506 Status read 2 failed
1.155442 send: Q1
1.215440 read: Q1
1.215539 blazer_status: short reply
1.215562 Status read 3 failed
1.215581 Trying mustek protocol…
1.219435 send: QS
1.471366 read: (235.6 235.6 235.6 — 50.1 13.6 –.- 00001001
1.471590 blazer_status: non numerical value [---]
1.471645 blazer_status: non numerical value [--.-]
1.471687 Status read in 1 tries
1.471706 Supported UPS detected with mustek protocol
1.475396 send: F
1.599348 read: #230.0 002 12.00 50.0
1.599536 Ratings read in 1 tries
1.603375 send: I
1.663341 read: I
1.663408 blazer_vendor: short reply
1.663429 Vendor information read 1 failed
1.667352 send: I

Broadcast Message from ….
(somewhere) at 0:45 …

Communications with UPS Z3_700@localhost lost

1.727365 read: I
1.727466 blazer_vendor: short reply
1.727488 Vendor information read 2 failed
1.731350 send: I
1.791325 read: I
1.791403 blazer_vendor: short reply
1.791423 Vendor information read 3 failed
1.791440 Vendor information unavailable
1.791462 Battery runtime will not be calculated (runtimecal not set)
1.795338 send: QS
2.047274 read: (235.6 235.6 235.6 — 50.1 13.6 –.- 00001001
2.047437 blazer_status: non numerical value [---]
2.047481 blazer_status: non numerical value [--.-]
2.047805 dstate_init: sock /var/run/nut/blazer_usb-Z3_700 open on fd 5
2.051302 send: QS
2.303228 read: (236.1 236.1 236.1 — 50.1 13.6 –.- 00001001
2.303385 blazer_status: non numerical value [---]
2.303427 blazer_status: non numerical value [--.-]

Le driver

Vous devez recharger les fichiers de configuration après chaque modification :

$ sudo udevadm control –reload_rules
$ sudo udevadm control trigger

Note : ces commandes sont optionnelles pour les onduleurs USB.

Test de la communication entre le driver et l’onduleur

$sudo upsdrvctl start

Network UPS Tools – UPS driver controller 2.4.3
Network UPS Tools – Megatec/Q1 protocol USB driver 0.03 (2.4.3)
Supported UPS detected with mustek protocol
Vendor information unavailable
Battery runtime will not be calculated (runtimecal not set)

Broadcast Message from user@Debian
(somewhere) at 23:16 …

Communications with UPS Z3_700@localhost established

upsd et upsmon

upsd communique avec le driver que nous venons de démarrer. Le moniteur upsmon communique avec le service upsd. De multiples moniteurs sur différentes machines peuvent partager le même onduleur physique. Le moniteur enverra la commande d’extinction de leur machine hôte.

Fichier du moniteur : /etc/nut/upsmon.conf

Fichier du serveur : /etc/nut/upsd.conf

# MAXAGE 15
# LISTEN 127.0.0.1 3493

Ces fichiers doivent être protégés contre la lecture des utilisateurs !

$ sudo chown root:nut /etc/nut/*
$ sudo chmod 640 /etc/nut/*

Redémarrer le service nut

$ sudo /etc/init.d/nut restart

Regardez vos log système pour voir si tout s’est bien passé.
Client ups

Le programme upsc permet d’interroger votre onduleur

$ upsc -L localhost donne une liste des onduleurs géré par le serveur sur l’hôte.

$ upsc z3_700

battery.voltage: 13.60
battery.voltage.nominal: 12.0
beeper.status: enabled
device.type: ups
driver.name: blazer_usb
driver.parameter.pollinterval: 2
driver.parameter.port: /dev/hidraw0
driver.parameter.productid: 5161
driver.parameter.vendorid: 0665
driver.version: 2.4.3
driver.version.internal: 0.03
input.current.nominal: 2.0
input.frequency: 50.1
input.frequency.nominal: 50
input.voltage: 227.9
input.voltage.fault: 227.9
input.voltage.nominal: 230
output.voltage: 227.9
ups.delay.shutdown: 30
ups.delay.start: 180
ups.productid: 5161
ups.status: OL
ups.type: offline / line interactive
ups.vendorid: 0665

Tout est prêt pour que votre onduleur prévienne le système lors des coupures du secteur.

Par défaut, upsmon attendra le signal de batterie critique pour déclencher l’arrêt de la machine ; ce qui peut se produire après une vingtaine de minutes voire 30 minutes s’il n’est pas trop chargé.

Note : Pour arrêter votre onduleur à distance :

$upsdrvctl shutdown

Often it is necessary for testing purposes to recreate the networking conditions found in a high latency network, such as a satellite link.

Firstly create a network bridge that can be placed inbetween the test network and its router.

To increase network latency use the following command:

tc qdisc add dev eth0 root netem delay 2000ms

which will delay every IP packet going through the bridge by 2 seconds.

To reset this delay and remove the 2 seconds of latency:

tc qdisc del dev eth0 root

viaEmulating a high latency network connection using Linux and TC.

IP packet drop can be easily emulated on any section of network using a Linux Bridge and a single iptables command:

iptables -t mangle -A FORWARD -m statistic –mode random –probability 0.01 -j DROP

(where probability is expressed as a value between 0 and 1)

If the intention is to emulate packet drop to the local Linux system not using a bridge, use the INPUT chain:

iptables -t mangle -A INPUT -m statistic –mode random –probability 0.01 -j DROP

To remove the random packet drop and restore the connection to normal operation either change -A to -D in the above commands, or flush the iptables with:

iptables -t mangle -F FORWARD or iptables -t mangle -F INPUT

viaEmulating a network connection with packet drop.

Pour la console système

kernel : vga=

Colors ( depth) 640×480 800×600 1024×768 1280×1024 1600×1200 —————+——-+——-+——–+———+———

256 ( 8 bit)| 769 771 773 775 796

32,768 (15 bit)| 784 787 790 793 797

65,536 (16 bit)| 785 788 791 794 798

16.8M (24 bit)| 786 789 792 795 799

viaShrimpWorks » Change your console resolution and colour depth.

Chroot SSH et PTY allocation avec Debian Lenny

Pour mettre en place des serveurs de backup, j’utilise un script chroot-ssh.sh qui permet la construction d’un chroot minimal pour faire tourner un serveur SSH et faire du rsync. Avec la mise-à-jour vers Lenny, l’allocation PTY réalisée par SSHD change : il ne semble plus possible de mettre en place un serveur SSH sans monter PROCFS et DEVPTS. Sans cela, on rencontre les erreurs suivantes côté serveur SSH :

debug1: Allocating pty
openpty: No such file or directory
session_pty_req: session 0 alloc failed

Si uniquement DEVPTS est monté, et pas PROCFS :
debug1: Allocating pty
openpty: returns device for which ttyname fails.

Voici donc les étapes pour lancer le serveur SSH chrooté avec Debian Lenny :
#  chroot /backup/jails/myserver mount -t proc proc-chroot /proc/
#  chroot /backup/jails/myserver mount -t devpts devpts-chroot /dev/pts/
#  chroot /backup/jails/myserver /usr/sbin/sshd &gt; /dev/null

Creating a 4-disk RAID10 using mdadm

Since I can’t seem to find instructions on how to do this (yet)…

I’m going to create a 4-disk RAID10 array using Linux Software RAID and mdadm. The old way is to create individual RAID1 volumes and then stripe a RAID0 volume over the RAID1 arrays. That requires creating extra /dev/mdN nodes which can be confusing to the admin that follows you.

1) Create the /dev/mdN node for the new RAID10 array. In my case, I already have /dev/md0 to /dev/md4 so I’m going to create /dev/md5 (note that « 5″ appears twice in the command).

# mknod /dev/md5 b 9 5

2) Use fdisk on the (4) drives, create a single primary partition of type « fd » (Linux raid autodetect). Note that I have *nothing* on these brand new drives, so I don’t care if it wipes out data.

3) Create the mdadm RAID set using 4 devices and a level of RAID10.

# mdadm –create /dev/md5 -v –raid-devices=4 –chunk=32 –level=raid10 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1

Which will result in the following output:

mdadm: layout defaults to n1

mdadm: size set to 732571904K

mdadm: array /dev/md5 started.

# cat /proc/mdstat

Personalities : [raid1] [raid10]

md5 : active raid10 sdf1[3] sde1[2] sdd1[1] sdc1[0]

1465143808 blocks 32K chunks 2 near-copies [4/4] [UUUU]

[>....................] resync = 0.2% (3058848/1465143808) finish=159.3min speed=152942K/sec

As you can see, we get around 150MB/s from the RAID10 array. The regular RAID1 arrays only have about 75MB/s throughput (same as a single 750GB drive).

A final note. My mdadm.conf file is completely empty on this system. That works well for simple systems, but you’ll want to create a configuration file in more complex setups.

Updates:

Most of the arrays that I’ve built have been based on 7200 RPM SATA drives. For small arrays (4 disks w/ a hot spare), often you can find enough ports on the motherboard. For larger arrays, you’ll need to look for PCIe SATA controllers. I’ve used Promise and 3ware SATA RAID cards. Basically any card that allows the SATA drives to be seen and is supported directly in the Linux kernel are good bets (going forward we’re going to switch to Areca at work).

Example of creating a 6-drive RAID10 array:

# mdadm –create /dev/md5 –raid-devices=6 –spare-devices=1 –layout=n2 –level=raid10 /dev/sd[a-g]1

In this case, we’re setting up a 6-drive RAID10 array along with 1 hot-spare. Disks sda to sdg all have a single partition on them, tagged as « fd » Linux RAID in fdisk.

« n2″ is the default RAID10 layout for mdadm and is a good default that provides balanced performance for reads and writes.

« f2″ is an optional layout that has better read performance, but worse write performance.

viatgharold.com: Tech Blog: Creating a 4-disk RAID10 using mdadm.