Matteo Michelini

Friday, November 21, 2008

HOWTO send mails through the shell

# cat mail_body.txt | mail -s "This is the subject" -F from@email.com -t to@email.com

You can use echo "This is the body" instead of cat mail_body.txt

HOWTO verify tarball corruption

# tar cpf archive.tar archive/
# tar Wdf archive.tar

tar -W or tar --verify checks the tar archive with the filesystem dir
The errors are redirected on stderr ( 2> tar_error.txt )

# gzip archive.tar
# gzip -tvv archive.tar.gz

or

# bzip2 archive.tar
# bzip2 -tvv archive.tar.bz2

output is redirected to stderr (even if the test is successful) and is similar to

archive.tar.bz2: OK

You can test it redirecting the output to a file $TEST and then using

if [ "$(awk '{print $2}' $TEST)" != "OK" ]; then
#manage error
exit
else
...
fi

Sunday, November 16, 2008

Colored ls output in OpenBSD

# pkg_add -i colorls

# nano -w ~/.profile
[ ...
  alias ls='colorls -G'
  ... ]

Thursday, November 13, 2008

HOWTO manage OpenBSD packages

Sync and Install a new package with the interactive mode (-i) (eg. pkg_add -i vim)

# export
 PKG_PATH=http://mirror.switch.ch/ftp/pub/OpenBSD/4.3/
packages/`machine -a`/
{insert the previous line into /root/.profile to save the variable}
# pkg_add -i [package]

List the packages that are installed into the system

# pkg_info

Install a package that was partially downloaded/installed

# pkg_info {you can see the partial-* package name}
# pkg_delete partial-....
# pkg_add -i [package]
or
# pkg_add -i -r -F conflicts [package]

Upgrade the packages into the system

# pkg_add -iu

HOWTO install Linux on a Mac Intel

  1. Resize the MacOS partition using `BootCamp Assistant` creating another partition (this will be your future root partition). 
  2. Download and install rEFIt. 
  3. Reboot your Mac with the Linux bootable CD. 
  4. Create the ext3 partition and set it `bootable`.
  5. Reboot the machine and use the rEFIt tool to sync the GPT/MBR table.
  6. Reboot the machine with the Linux bootable CD and complete the installation process. 
  7. Install LILO into the same Linux partition (NOT into the MBR) instead of GRUB (grub doesn't support the ext3 with 256inode yet) 

Now your dualboot is ready. If you want to create a swap partition create a file into the Linux partition with dd and modify your /etc/fstab 

This is the output of diskutil list on MacOS X

# diskutil list
/dev/disk0
#:         TYPE NAME              SIZE       IDENTIFIER
0:   GUID_partition_scheme      *149.1 Gi       disk0
1:            EFI                200.0 Mi      disk0s1
2:   Apple_HFS Macintosh HD      127.9 Gi      disk0s2
3:            EFI                 20.9 Gi      disk0s3
#

HOWTO rank mirrors in ArchLinux

# pacman -Sy python

[sync the db and install python]
# mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirror-source
# vi /etc/pacman.d/mirror-source
[remove # before 'Server=' from the Europe servers]
# rankmirrors /etc/pacman.d/mirror-source > /etc/pacman.d/mirrorlist
# pacman -Syu [sync the db and upgrade the whole system]

Colored ls output in MacOS X Terminal

$ cat ~/.profile


export CLICOLOR=true
export LSCOLOR="exgxcxdxcxegedabagacad"
export EDITOR=/usr/bin/vim


Thanks to Marco Muccinelli @ www.melive.org

HOWTO setup a TFTP Server on MacOS X for saving the CISCO Router config

Download and install MacPorts from http://www.macports.org


# port -d selfupdate
[verbose output for port update]
# port search tftp
tftp-hpa net/tftp-hpa 0.48 Enhanced port of the BSD TFTP server
# port install tftp-hpa
[output for tftp download/compilation/installation]

The root dir of the TFTP server is /private/tftpboot

# cd /private/tftpboot
# touch router-confg
# chmod 666 router-confg

Lets use the TFTP server from the CISCO Router to same the startup-config

Router# copy start tftp
Address or name of remote host []? 10.10.10.51
Destionation filename []?router-confg
!!
2725 bytes copied in 1.300 secs (2096 bytes/sec)
Router#

HOWTO connect your Mac to the CISCO Router/Switch CLI

Buy a Serial DB9 male to USB like this one: http://www.iogear.com/product/GUC232A/


Download and install the `USB to Serial Driver for MacOS X` at http://sourceforge.net/projects/osx-pl2303

Now you must be able to see the following

$ ls /dev/tty.*
/dev/tty.Bluetooth-Modem
/dev/tty.Bluetooth-PDA-Sync
/dev/tty.PL2303-0000101D
$

Power your CISCO Router, plugin your rollover cable into the router and connect it to the DB9 - USB adapter and write the following

$ screen /dev/tty.PL2303-0000101D 9600
[Enter]
Router>

Ctrl+a k to exit screen