Welcome to zewaren.net. This site presents myself and mostly archives the solutions to some problems I once had.

How to use bazaar through a HTTP Proxy

Not so frequently asked questions and stuff: 

Bazaar Logo

How to use bazaar through a HTTP Proxy

This will quickly explain how to use bzr trough a HTTP proxy with authentication. We want to branch AND push. This requires the plugin bzr-plugins.

Windows

Download and install the plugin

Download the plugin:

>set http_proxy = http://user:pass@proxy:port
>set https_proxy = http://user:pass@proxy:port
>bzr branch lp:bzr-webdav
You have not informed bzr of your Launchpad ID, and you must do this to
write to Launchpad or access private data.  See "bzr help launchpad-login".
Branched 73 revision(s).

Copy it to C:\Program Files (x86)\Bazaar\plugins or wherever you installed bazaar, and rename it to webdav.

>move bzr-webdav webdav
        1 dir(s) moved.

>copy webdav "c:\Program Files (x86)\Bazaar\plugins"
webdav\COPYING.txt
webdav\info.py
webdav\NOTES
webdav\setup.py
webdav\TODO
webdav\webdav.py
webdav\__init__.py
        7 file(s) copied.

Install the plugin:

>cd "c:\Program Files (x86)\Bazaar\plugins\webdav"

>python.exe setup.py install
running install
running build
running build_py
copying .\info.py -> build\lib\bzrlib\plugins\webdav
copying .\webdav.py -> build\lib\bzrlib\plugins\webdav
copying .\__init__.py -> build\lib\bzrlib\plugins\webdav
copying tests\dav_server.py -> build\lib\bzrlib\plugins\webdav\tests
copying tests\test_webdav.py -> build\lib\bzrlib\plugins\webdav\tests
copying tests\__init__.py -> build\lib\bzrlib\plugins\webdav\tests
running install_lib
running install_egg_info
Removing c:\Python27\Lib\site-packages\bzr_webdav-1.12.3-py2.7.egg-info
Writing c:\Python27\Lib\site-packages\bzr_webdav-1.12.3-py2.7.egg-info

>bzr plugins
...
webdav 1.12.3dev
  An http transport, using webdav to allow pushing.
...

Use the plugin

>set http_proxy = http://user:pass@proxy:port
>bzr push http+webdav://bzr.example.org
HTTP bzr.example.org, Realm: 'SOMEREALM' username: test
HTTP test@bzr.example.org, Realm: 'SOMEREALM' password:
Pushed up to revision 7.

Ubuntu

Download and install the plugin

Configure apt to use the proxy (if necessary):

#export http_proxy = http://user:pass@proxy:port

Add the following lines to your source.list file:

deb http://ppa.launchpad.net/bzr/daily/ubuntu lucid main 
deb-src http://ppa.launchpad.net/bzr/daily/ubuntu lucid main 

Follow the link at https://launchpad.net/~bzr/+archive/daily to get the signing key: http://keyserver.ubuntu.com/pks/lookup?op=get&search=0xD702BF6B8C6C1EFD and save it to a file.

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.0.10

mI0ESXSSBgEEAKqURmlbPIQuqZJ6Gip/Y4hElzJzW8po0k3cQkT+xc7pqqa9QVKi2W2L5XzU
1gXKpzF+dZ+JcVlNQUNLFWeLhLF/Viw5zZTGW4evsEO1Vilp5VHS2YPmJBkibIlZ5UJ+qhaM
lOkf66mFglogG5GZqktPStO9shZfx2MqUK/t6RFBABEBAAG0I0xhdW5jaHBhZCBQUEEgZm9y
IEJhemFhciBEZXZlbG9wZXJziEYEEBECAAYFAkl3aasACgkQ/vSRAed+jpjzngCgu79TtIck
IwSTAuYbrrziZH7oFjwAoKrTHhu41jQKgFhiW7t88JA6LCUMiEYEEBECAAYFAknOwVsACgkQ
9rPTxuzZSv1+IACfVS9KKRtFUF4eS8tLvpVahzkSJsEAoMP3/ASzUP5sHa9pf/UMyzpoaC9H
iEYEEBECAAYFAknS5Z0ACgkQrZORep7Yx+rC1gCglr4g4riENgChBciGIenDAOFgpdUAn3FI
ghBiV+VuBYIE3UlNkc3aRUf5iEYEEBECAAYFAkp/uc0ACgkQuL+o2Md08jv3ogCglVdsjTpj
IVgZJuss2J/oNqAlqIoAoIDctdsxd0iX3tBodkz00+ZpOn/5iLYEEwECACAFAkl0kgYCGwMG
CwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRDXAr9rjGwe/U17A/9DhXbxAzX2czO+KypV3OSz
/p5CjdnOIUbf6LHDOoH7Bxq4a3MUBve5jPe764cjmPPqYElbrtzky9byLjatUO5gSFo2M20I
LajoYUW57is5Fu+m1Y7IHRfLonC44od9XWPvpwROQ00/fqPGHmri5/mPJiaW0N3dniYu7a23
vdaVuQ==
=6i6T
-----END PGP PUBLIC KEY BLOCK-----

Import said key:

#gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --import somekey 
gpg: clé 8C6C1EFD: « Launchpad PPA for Bazaar Developers » une nouvelle signature
gpg: Quantité totale traitée: 1
gpg:         nouvelles signatures: 1
gpg: aucune clé de confiance ultime n'a été trouvée

Install bzr-webdav using the new repository (this will also fetch the latest version of bzr and bzrlib).

#apt-get update
#apt-get install bzr-webdav

Check that bzr-webdav is installed and loaded

#bzr plugins
...
webdav 1.12.2
  An http transport, using webdav to allow pushing.
...

Use bzr-webdav

# bzr branch http://bzr.example.org
HTTP bzr.example.org, Realm: 'SOMEREALM' username: test
HTTP test@bzr.example.org, Realm: 'SOMEREALM' password: 
Branched 8 revisions.                    

# #Commit something

# bzr push http+webdav://bzr.example.org
HTTP bzr.example.org, Realm: 'SOMEREALM' username: test                            
HTTP test@bzr.example.org, Realm: 'SOMEREALM' password: 
Pushed up to revision 9.   

If your proxy configuration is system wide, you can even use the explorer:
Bazaar explorer pushing trough a proxy to a webdav repository

Remember the credentials

authentication.conf:

[EXAMPLE]
scheme=http
host=bzr.example.org
path=/
user=webdav_test
password=webdav_password

Sources:

How to use jails with epair with FreeBSD 8.2

Not so frequently asked questions and stuff: 

Introduction

System used:

FreeBSD testjail.example.net 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Thu Aug 11 09:10:23 CEST 2011     root@testjail.example.net:/usr/obj/usr/src/sys/JAILKERNEL  amd64

Build and install a kernel including VIMAGE, epair and briged interfaces

Configure the kernel: (/usr/src/sys/amd64/conf/JAILKERNEL)

include GENERIC

cpu             HAMMER
ident           JAILKERNEL

# Firewalling
device          pf
device          pflog

# Virtual networking for jail
options         VIMAGE
device          epair
device          if_bridge

# The nullFS to mount local directory
options         NULLFS

Make and install the kernel:

cd /usr/src
make buildkernel KERNCONF=JAILKERNEL
make installkernel KERNCONF=JAILKERNEL
reboot

Create the jail's environement

mkdir /usr/jails/testjail
cd /usr/src
make installworld DESTDIR=/usr/jails/testjail
make distribution DESTDIR=/usr/jails/testjail
echo 'hostname="testjail.example.com"' >> /usr/jails/testjail/etc/rc.conf
echo 'nameserver 8.8.8.8"' >> /usr/jails/testjail/etc/resolv.conf
mkdir /usr/jails/testjail/usr/ports

Start and use the jail manually

Start the jail:

# jail -c vnet name=testjail host.hostname=testjail path=/usr/jails/testjail persist
# jls
   JID  IP Address      Hostname                      Path
      1  -                      testjail                               /usr/jails/testjail

Create the virtual ethernet cable:

# ifconfig epair0 create
epair0a
# ifconfig epair0b vnet 1

Create the bridge:

# ifconfig bridge create
bridge0
# ifconfig bridge0 addm epair0a addm bge0

Configure the network on both sides:

# ifconfig bge0 192.168.1.10/24
# ifconfig epair0a 192.168.1.11/24
# jexec testjail ifconfig epair0a 192.168.1.12/24
# jexec testjail ifconfig
lo0: flags=8008 metric 0 mtu 16384
        options=3
epair0b: flags=8843 metric 0 mtu 1500
        ether 02:06:d7:00:07:0b
        inet 192.168.1.12 netmask 0xffffff00 broadcast 192.168.3.255
        inet6 fe80::6:d7ff:fe00:70b%epair0b prefixlen 64 scopeid 0x2
        nd6 options=3

Test the connection:

# jexec testjail ping -c 1 192.168.1.11
PING 192.168.1.11 (192.168.1.11): 56 data bytes
64 bytes from 192.168.1.11: icmp_seq=0 ttl=64 time=0.059 ms

--- 192.168.1.11 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.059/0.059/0.059/0.000 ms

# jexec web ping -c 1 192.168.1.10
PING 192.168.1.10 (192.168.1.10): 56 data bytes
64 bytes from 192.168.1.10: icmp_seq=0 ttl=64 time=0.094 ms

--- 192.168.1.10 ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.094/0.094/0.094/0.000 ms

Stop the jail:

# jail -r testjail
enceinte# jls
   JID  IP Address      Hostname                      Path

Clean the network:

# ifconfig epair0a destroy
# ifconfig bridge0 destroy

Start the jail automatically

As of 2011/08/01, /etc/rc.d/jail has problems using the new jail command (v2), so you must patch it if you want to use vnets:
http://www.freebsd.org/cgi/query-pr.cgi?pr=142972

In /etc/rc.conf:

#
# Jails networking
#
cloned_interfaces="bridge0"
ifconfig_bridge0="addm bge0"

#
# Jails configuration
#
jail_enable="YES"
jail_v2_enable="YES"
jail_list="testjail"

jail_testjail_name="testjail"
jail_testjail_hostname="testjail.example.net"
jail_testjail_devfs_enable="YES"
jail_testjail_rootdir="/usr/jails/testjail"
jail_testjail_vnet_enable="YES"
jail_testjail_exec_prestart0="ifconfig epair0 create"
jail_testjail_exec_prestart1="ifconfig bridge0 addm epair0a"
jail_testjail_exec_prestart2="ifconfig epair0a up"
jail_testjail_exec_earlypoststart0="ifconfig epair0b vnet testjail"
jail_testjail_exec_afterstart0="ifconfig lo0 127.0.0.1"
jail_testjail_exec_afterstart1="ifconfig epair0b 192.168.1.12 netmask 255.255.255.0 up"
jail_testjail_exec_afterstart2="route add default 192.168.1.1"
jail_testjail_exec_afterstart3="/bin/sh /etc/rc"
jail_testjail_exec_poststop0="ifconfig bridge0 deletem epair0a"
jail_testjail_exec_poststop1="ifconfig epair0a destroy"

Then:

# /etc/rc.d/jails start testjail

# jexec web ping -c 1 example.net
PING example.net (192.0.43.10): 56 data bytes
64 bytes from 192.0.43.10: icmp_seq=0 ttl=243 time=94.903 ms

--- example.net ping statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 94.903/94.903/94.903/0.000 ms

Sources:

How to use FreeBSD as a ISCI Target and Initiator (with CHAP)

Not so frequently asked questions and stuff: 

How to use FreeBSD as a ISCSI Target and Initiator

FreeBSD 8 as a Target

System used:

uname -a
FreeBSD lan-test-pbx.example.fr 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:48:17 UTC 2009     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

The server's IP address is 192.168.3.156 and the network is 192.168.3.0/24.

Install the iscsi target port:

cd /usr/ports/net/istgt/
make install clean

Copy and edit the sample configuration files

cd /usr/local/etc/istgt
cp auth.conf.sample auth.conf
cp istgt.conf.sample istgt.conf
cp istgtcontrol.conf.sample istgtcontrol.conf

istgt.conf:

[Global]
  Comment "Global section"
  NodeBase "iqn.2011-06.net.example.tests"
  DiscoveryAuthMethod CHAP
  DiscoveryAuthGroup AuthGroup9999

  #The following values were not editied
  PidFile /var/run/istgt.pid
  AuthFile /usr/local/etc/istgt/auth.conf
  MediaDirectory /var/istgt
  LogFacility "local7"

  Timeout 30
  NopInInterval 20

  MaxSessions 16
  MaxConnections 4
  MaxR2T 32
  MaxOutstandingR2T 16
  DefaultTime2Wait 2
  DefaultTime2Retain 60
  FirstBurstLength 262144
  MaxBurstLength 1048576
  MaxRecvDataSegmentLength 262144
  InitialR2T Yes
  ImmediateData Yes
  DataPDUInOrder Yes
  DataSequenceInOrder Yes
  ErrorRecoveryLevel 0

#Unit controller
[UnitControl]
  Comment "Internal Logical Unit Controller"
  AuthMethod CHAP Mutual
  AuthGroup AuthGroup10000
  Portal UC1 127.0.0.1:3261
  Netmask 127.0.0.1

#Portal of the Test Disk
[PortalGroup1]
  Comment "SINGLE PORT TEST"
  Portal DA1 192.168.3.156:3260

#Initiators for the Test Disk
[InitiatorGroup1]
  Comment "Initiator Group1"
  InitiatorName "iqn.2011-06.net.example.tests:virtual175"
  Netmask 192.168.3.0/24

#Test Disk
[LogicalUnit1]
  Comment "Test Disk"
  TargetName testdisk
  TargetAlias "ISCSI Test Disk"

  Mapping PortalGroup1 InitiatorGroup1
  AuthMethod CHAP
  AuthGroup AuthGroup1
  UseDigest Auto
  UnitType Disk
  LUN0 Storage /usr/local/iscsi/testdisk 100MB


auth.conf:

[AuthGroup1]
  Comment "Group for the Test Disk"
  Auth "iqn.2011-06.net.example.tests:virtual175"  "between12and16"

[AuthGroup9999]
  Comment "Group for discovery"
  Auth "iqn.2011-06.net.example.tests:discoverer"  "discovermenow"

[AuthGroup10000]
  Comment "Group for unit controller"
  Auth "ctluser" "test" "mutualuser" "mutualsecret"

istgtcontrol.conf:

[Global]
  Comment "Sample Configuration"
  Timeout 60

  AuthMethod CHAP Mutual
  Auth "ctluser" "test" "mutualuser" "mutualsecret"

  Host localhost
  Port 3261

  TargetName "iqn.2011-06.net.example.tests:testdisk"
  Lun 0

  Flags "ro"
  Size "auto"

Create the disk:

dd if=/dev/zero of=/usr/local/iscsi/testdisk bs=`expr 1024 \* 1024` count=100

Restart the server:

$/usr/local/etc/rc.d/istgt restart
Starting istgt.
istgt version 0.4 (20110223)
traditional mode
LU1 HDD UNIT
LU1: LUN0 file=/usr/local/iscsi/testdisk, size=104857600
LU1: LUN0 204800 blocks, 512 bytes/block
LU1: LUN0 100MB storage for iqn.2011-06.net.example.tests:testdisk
LU1: LUN0 command queuing disabled

Test the connection:

$istgtcontrol list
lun0 storage "/usr/local/iscsi/testdisk" 104857600
DONE LIST command

Windows XP as an initiator

Download and install the Microsoft iSCSI Software Initiator Version 2.08.

Start the initiator in your start menu. Configure it to have the right node name:
Image

Add a new portal to activate the discovery:
Image

Log in to the target:
Image

The disk is now present and can be formatted (here in FAT32).
Image

Once mounted, files and folders can be created:
Image

Once you're done, log off the target to disconnect it:
Image

FreeBSD 8 as an initiator

System used:

uname -a
FreeBSD fbsd.localdomain 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Jun 10 10:17:58 CEST 2011     root@fbsd.localdomain:/usr/obj/usr/src/sys/ISCSIKERNEL  i386

Discovery

Without CHAP:

$iscontrol -d -t 192.168.3.156 firstBurstLength=65535 maxBurstLength=262144 InitiatorName=iqn.2011-06.net.example.tests:virtual175
0x0201: Authentication failure

With CHAP:

$iscontrol -d -t 192.168.3.156 firstBurstLength=65535 maxBurstLength=262144 InitiatorName=iqn.2011-06.net.example.tests:virtual175 authMethod=CHAP chapIName=iqn.2011-06.net.example.tests:discoverer chapSecret=discovermenow TargetName=iqn.2011-06.net.example.tests:testdisk TargetAddress=192.168.3.156:3260,1

Connection

Configure the connection in /etc/isci.conf:

port = 3260

testdisk {
  targetaddress = 192.168.3.156:3260,1
  targetname = iqn.2011-06.net.example.tests:testdisk
  initiatorname = iqn.2011-06.net.example.tests:virtual175
  authmethod = CHAP
  chapIName = iqn.2011-06.net.example.tests:virtual175
  chapsecret = between12and16
  firstBurstLength = 65535
  maxBurstLength = 262144
}

Connect:

$iscontrol -c /etc/iscsi.conf -n testdisk
iscontrol[4562]: running
iscontrol[4562]: (pass0:iscsi0:0:0:0):  tagged openings now 0

Check:

$ls -l /dev/iscsi*
crw-------  1 root  wheel    0,  29 Jun 21 10:02 /dev/iscsi
crw-------  1 root  wheel    0,  29 Jun 21 10:02 /dev/iscsi
crw-------  1 root  wheel    0,  95 Jun 22 14:04 /dev/iscsi0

$ls -l /dev/da*
crw-r-----  1 root  operator    0,  98 Jun 22 14:04 /dev/da0
crw-r-----  1 root  operator    0,  99 Jun 22 14:04 /dev/da0s1

The disk contains a single partition formatted as FAT32 by Windows.

$mount -t msdosfs /dev/da0s1 /mnt/iscsi
$ls -l /mnt/iscsi/
total 5
drwxr-xr-x  1 root  wheel  1024 Jun  8 16:26 System Volume Information
-rwxr-xr-x  1 root  wheel     3 Jun  8 16:26 fichier1.txt
-rwxr-xr-x  1 root  wheel     6 Jun  8 16:26 fichier2.txt
drwxr-xr-x  1 root  wheel  1024 Jun  8 16:26 poulet
-rwxr-xr-x  1 root  wheel     8 Jun 22 11:23 truite.txt

The files and folders are present.

When you're done:

$umount /mnt/iscsi/

$ps aux | grep iscontrol
root   4562  0.0  0.5  3460  1312  ??  Is    2:04PM   0:00.01 iscontrol -c /etc/iscsi.conf -n testdisk
$kill -s HUP 4562
iscontrol[4562]: trapped signal 1
trapped signal 1
iscontrol: supervise going down
iscontrol[4562]: sess flags=20000407
iscontrol[4562]: terminated

Sources:

How to configure the SPA500S Attendant Console with Asterisk/FreePBX

Not so frequently asked questions and stuff: 

What we have:

  • A Cisco SPA525G IP Phone with a SPA500S Attendant Console
  • A FreePBX Server
  • Some other SIP phones

We want to configure FreePBX and the attendant Console.

FreePBX

Make sure that picking up calls work.

See http://www.freepbx.org/support/documentation/howtos/how-to-use-callgroups-and-pickgroups to set up pickgroups.

Apart from that, FreePBX should configure the hints correctly without any additional configuration.

The phone


Make sure that the phones are allowed to dial feature codes like **1234. On the SPA525G, you must modify the dialplan in the phone's configuration (set it to something like (*xx.|**xx.|xx.)).

The Attendant Console


Attendant Console Call Pickup Code: **# (feature code for Directed Call Pickup + #, # will be replaced by the extension number). If you set it to *8 (feature code for Asterisk General Call Pickup), the console will pick _any_ ringing phone, so if two of them are ringing at the same time, you don't know which one will get chosen.

Unit keys: fnc=sd+cp+blf;sub=extension@server;nme=extension
Exemple: fnc=sd+cp+blf;sub=1742@192.168.3.156;nme=1742

Sources

Serve clonezilla using PXE on a freebsd host with nfs.

PXE: 
Not so frequently asked questions and stuff: 

System used

The server system used was a soekris net4801 running freebsd.

uname -a
FreeBSD net4801 8.2-RELEASE FreeBSD 8.2-RELEASE #0: Fri Feb 18 02:24:46 UTC 2011     root@almeida.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  i386

Ports

You will need the following ports:

  • ftp/tftp-hpa (I tried using the builtin tftp server but it sometimes failed for no reason).
  • net/isc-dhcp41-server (or any other dhcp server you fancy)

DHCP server

Configure your dhcp server to serve pxelinux.0

#/usr/local/etc/dhcpd.conf
subnet 192.168.242.0 netmask 255.255.255.0 {
  range 192.168.242.4 192.168.242.250;
  next-server 192.168.242.3;
  filename "pxelinux.0";
}

TFTP server

Configure your tftp server to listen and serve the right folder.

#/etc/inetd.conf

#if you are using tftp:
tftp   dgram   udp     wait    root    /usr/libexec/tftpd      tftpd -l -s /usr/local/tftpboot

#if you are using tftp-hpa:
tftp    dgram   udp     wait    root    /usr/local/libexec/in.tftpd     in.tftpd -p -s /usr/local/tftpboot

Check that the server is running:

netstat -a | grep tftp
udp4       0      0 *.tftp                 *.*

TFTP files

  • Copy the kernel (vmlinux) and the initrd (initrd.img) from the cd/usb/zip to the folder /images/clonezilla.
  • Download or find elsewhere a working copy of pxelinux.0 and copy it to /
  • Add an entry to the file pxelinux.cfg/default
ls /usr/local/tftpboot/
images          pxelinux.0      pxelinux.cfg

ls /usr/local/tftpboot/pxelinux.cfg/
default

ls /usr/local/tftpboot/images/clonezilla/
initrd.img              vmlinuz

cat pxelinux.cfg/default
MENU LABEL Clonezilla live
DEFAULT clonezillanfs

label clonezillanfs
kernel images/clonezilla/vmlinuz
append initrd=images/clonezilla/initrd.img boot=live live-config noswap union=aufs netboot=nfs nfsroot=192.168.242.3:/usr/local/clonezilla_nfs ocs_live_run="ocs-live-general" ocs_live_extra_param="" ocs_live_keymap="" ocs_live_batch="no" ocs_lang="" vga=788

NFS Server

Configure your nfs server to serve the folder /usr/local/clonezilla_nfs.

cat /etc/exports
/usr/local/clonezilla_nfs    -network 192.168.242 -mask 255.255.255.0

Copy or mount the cd into the folder.

ls /usr/local/clonezilla_nfs/
COPYING                 isolinux                syslinux
Clonezilla-Live-Version live                    utils

Run

Boot the client and use clonezilla.

References:

Android - Get a string (or any resource) dynamically by its name.

Not so frequently asked questions and stuff: 

res\values\truc.xml:

LapinPouletSaucisse

quelquepart.java:

for (Integer i=1; i

UTF-8 ISO8859-1 quick cheatsheet

Not so frequently asked questions and stuff: 

Here is a quick reference about utf-8 decoding/encoding:

Image

How to format a file size in Excel (B, KB, MB, GB)

Not so frequently asked questions and stuff: 

In French:

=SI(A1>=1024*1024*1024; TEXTE(A1/(1024*1024*1024); "0")&" GiB";
SI(A1>=1024*1024; TEXTE((A1/(1024*1024)); "0")&" MiB"; 
SI(A1>=1024; TEXTE((A1/(1024)); "0")&" KiB";
TEXTE(A1; "0")&" B")))

In English:

=IF(A1>=1024*1024*1024; TEXT(A1/(1024*1024*1024); "0")&" GiB";
IF(A1>=1024*1024; TEXT((A1/(1024*1024)); "0")&" MiB"; 
IF(A1>=1024; TEXT((A1/(1024)); "0")&" KiB";
TEXT(A1; "0")&" B")))

Using MySQL through ODBC on FreeBSD.

Not so frequently asked questions and stuff: 

Installation and configuration

Install the following ports:

  • databases/unixODBC
  • databases/mysql-connector-odbc

Use odbcinst to find where odbcinst.ini is located.

odbcinst -j
unixODBC 2.3.0
DRIVERS............: /usr/local/etc/odbcinst.ini
SYSTEM DATA SOURCES: /usr/local/etc/odbc.ini
FILE DATA SOURCES..: /usr/local/etc/ODBCDataSources
USER DATA SOURCES..: /root/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2

Edit /usr/local/etc/odbcinst.ini

cat /usr/local/etc/odbcinst.ini
[MySQL]
Description=ODBC for MySQL
Driver=/usr/local/lib/libmyodbc3.so
UsageCount=20001

Install the driver.

odbcinst -i -d -f /usr/local/etc/odbcinst.ini

Edit odbc.ini

cat /usr/local/etc/odbc.ini
[dsn_name]
Driver=MySQL
SERVER=localhost
PORT=3306
DATABASE=db_name
USER=user_name
PASSWORD=user_password
OPTION=4194304

Configure more options using this page: http://www.verbose.fr/mysql_5.1_en/connectors.html#myodbc-configuration-connection-parameters. Use FLAG_AUTO_RECONNECT to reconnect automatically.

List the available DSNs to check the config.

odbcinst -s -q
[dsn_name]

See also:

  • http://www.unixodbc.org/odbcinst.html
  • http://www.webaj.com/how-setup-mysql-dsn-datasbase-source-centos-myodbc-and-unixodbc-command-line.htm
  • http://wiki.freeswitch.org/wiki/Mod_spidermonkey_odbc#General_Configuration

Known problems

Auto reconnect does not work

Check the version of mysql-connector-odbc.

pkg_info | grep mysql-connector-odbc
mysql-connector-odbc-unixodbc-mysql51-3.51.26_3 ODBC driver for MySQL51 / unixodbc

The Mysql Bug #37179 states that FLAG_AUTO_RECONNECT does not work using versions prior to 3.51.27.
(http://bugs.mysql.com/bug.php?id=37179)
Upgrade the port if available, or correct the bug manually in connect.c before recompiling.

How to get yesterday's date in bash

Not so frequently asked questions and stuff: 

How to get yesterday's date in bash:

$date  +"%y-%m-%d"
10-11-14
$date -d @`expr $(date +%s) - 86400` +"%y-%m-%d"
10-11-13

For an unknown reason, the parameter @epoch is not documented in "man date" but it is in "info date".

Pages

Subscribe to Front page feed