Archive for the ‘linux’ Category.

Manage VMware virtual machines from the command line

To control VMware Workstation Virtual Machines from the command line use the vmrun utility. For instance, to stop a running virtual machine use this command:

# vmrun stop myvm.vmx

For a comprehensive guide on vmrun take a look at this document.

Convert EPS files to PNG images

Doxygen generates collaboration diagrams in EPS format. If you want to include these graphics in a Latex document that produces PDF output, you have to convert them, for example, to PNG format. To make the conversion we’re going to use Convert. Convert provides image conversion between different formats and belongs to the ImageMagick suite of tools. Just navigate to the directory containing the EPS files and type this command:

for var in `ls|grep eps`;do convert $var ${var}.png;done

This produces PNG images with an .eps.png extension. If you want to leave just the png extension run this python script:

1
2
3
4
#!/usr/bin/python
import os
for fname in os.listdir(os.getcwd()):
        os.rename(fname, fname.replace('.eps.png','.png'))

Video streaming with VLC

To start the video streaming execute:

# vlc -v -I rc movie.avi --sout "#standard{access=http,mux=ogg,dst=npserver.labplan.southpark:8080)

Since we’re using the remote control interface (-I rc), we don’t need a graphical environment. This feature is specially useful if we want to stream the video without starting an X Window session.

On the client side execute the following command to receive the stream:

# vlc http://npserver.labplan.southpark:8080

Setting up an IPv6 Bind DNS Server on Linux

If the DNS server isn’t installed on your Linux box, install it with the following command:

yum groupinstall "DNS Name Server"

We need to configure two things. First we need to specify the domains we’re going to resolve in named.conf. We will resolve the labplan.southpark domain.
Our DNS server will support both direct (name->ip) and reverse (ip->name) resolution.

According to APNIC the use of ip6.int is deprecated in favor of ip6.arpa for
reverse resolutions. However, since many programs still use it, we’re going to define
the ip6.int version as well. We need to add the following lines to named.conf:

zone "labplan.southpark" IN {
type master;
file "labplan.southpark.zone";
};
//deprecated
zone "0.0.0.0.0.0.0.0.0.0.0.0.1.c.e.f.ip6.int" {
type master;
file"reverse-fec1_64i.IP6.INT";
};
zone "0.0.0.0.0.0.0.0.0.0.0.0.1.c.e.f.ip6.arpa" {
type master;
file "reverse-fec1_64.IP6.ARPA";
};

Next we have to fill the zone records. The information for direct resolutions is stored on labplan.southpark.zone:

$TTL    86400
@               IN SOA  @       root (
		42              ; serial (d. adams)
		3H              ; refresh
		15M             ; retry
		1W              ; expiry
		1D )            ; minimum
 
          IN NS           ns6.labplan.southpark.
 
 
ns6		 IN      AAAA    fec0::20c:29ff:fe8f:8f16
customer	 IN      AAAA    fec0::20c:29ff:feff:4b37
npserver	 IN      AAAA    fec0::20c:29ff:fe4a:fae0
an		 IN      AAAA    fec0::20c:29ff:feb4:bee2

The PTR records used for reverse resolution are stored on reverse-fec1_64i.IP6.INT (deprecated ip6.int) and reverse-fec1_64.IP6.ARPA (recommended ip6.arpa). This is the ip6.arpa zone (to edit an ip6.int zone just replace arpa with int):

$TTL 3d ; Default TTL 
@       IN SOA 0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa. root (
                200906170       ; Serial number (YYYYMMdd)
                24h             ; Refresh time
                30m             ; Retry time
                2d              ; Expire time
                3d              ; Default TTL 
)
                                IN     NS     ns6.labplan.southpark.
7.3.b.4.f.f.e.f.f.f.9.2.c.0.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa.   IN PTR costumer.labplan.southpark.
0.e.a.f.a.4.e.f.f.f.9.2.c.0.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa.   IN PTR npserver.labplan.southpark.
2.e.e.b.4.b.e.f.f.f.9.2.c.0.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa.     IN PTR an.labplan.southpark.
6.1.f.8.f.8.e.f.f.f.9.2.c.0.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa.     IN PTR gw.labplan.southpark.
6.1.f.8.f.8.e.f.f.f.9.2.c.0.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa.     IN PTR ns6.labplan.southpark.

From this moment on everything should work fine. We can check the name resolution with dig:

# dig @::1 -t AAAA npserver.labplan.southpark
;; QUESTION SECTION:
;npserver.labplan.southpark.    IN      AAAA
 
;; ANSWER SECTION:
npserver.labplan.southpark. 86400 IN    AAAA    fec0::20c:29ff:fe4a:fae0

To check reverse resolution use dig’s -x flag:

#dig @::1 -x fec0::20c:29ff:fe4a:fae0
;; QUESTION SECTION:
;0.e.a.f.a.4.e.f.f.f.9.2.c.0.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa.INPTR
 
;; ANSWER SECTION:
0.e.a.f.a.4.e.f.f.f.9.2.c.0.2.0.0.0.0.0.0.0.0.0.0.0.0.0.0.c.e.f.ip6.arpa. 259200  IN  PTR  npserver.labplan.southpark.

Setting up Ethernet 802.1X Port Based Authentication on Linux

IEEE 802.1X provides authentication and authorization capabilities for WiFi and Ethernet networks. This article covers how to set up IEEE 802.1X authentication for Ethernet networks on Linux. For more articles see articles section.

Enable IPv6 routing on Linux

To enable IPv6 routing on your Linux box you can use the following command:

echo 1 > /proc/sys/net/ipv6/conf/all/forwarding

If you want to keep IPv6 routing enabled permanently, edit /etc/sysctl.conf and add the following line:

net.ipv6.conf.all.forwarding=1

Remember that IPv6 filtering rules are controlled via ip6tables.

Solving (or improving) Macbook keyboard layout problems on Linux

Apple laptops have a slightly different keyboard layout. Obviously the keyboard works fine on Mac OSX but has some minor problems on Linux and Windows. In my case I have a Spanish layout and the Alt key doesn’t work by default. Hence I am unable to type some characters (@ # |). If you come across the same problem, one solution is to change the keyboard layout from Spanish to US international. This way those specials characters are accessible by pressing the Shift key. Besides programming with the US layout is faster (e.g. / and ; just need one keystroke).

To change the keyboard layout in Centos type:

# system-config-keyboard --text

… and choose US layout.

Wordpress Complete Backup Solution

Backing up your data is very recommendable (if you don’t do it start now!) and can save you a few headaches. This posts explains how to backup your Wordpress installation. You need to take care of 2 things:

  • The Wordpress database
  • The Wordpress files (plugins, themes, etc.).

For backing up the database I recommend the wp-db-backup plugin, which can be configured to send a daily backup of your database to your mail account.

If for any reason you lose your Wordpress data, you can retrieve the backup from your mail and restore it with the following command:

mysql --default_character_set=utf8 -h hostname -u username -p database < mybackup.sql

You can obtain the host, username and database name from wp-config.php. The encoding is important. If you don’t specify it your restored posts can look pretty messy.

Following the previous steps your posts and configurations are protected and chances of losing them are very low. The next step is to backup the Wordpress files (plugins, themes, config files, etc.). To perform this task I recommend rsync. This excellent tool is included on Unix-based systems (Linux, Mac, etc.). There are binaries for Windows also. Rsync performs folder synchronization (bot remotely and locally). One of its main advantages is that it does incremental backups (i.e. it only transfers the changed files). I use rsync to synchronize my remote Wordpress installation with a local folder. This way, every time something changes in the server, these changes are transferred to my local computer. The rsync syntax is as follows:

rsync -avvb --delete --backup-dir=/Users/jorge/rsync/backup_$(date +%y%m%d%H%M) username@somebox.bluehost.com:/home4/username/public_html /Users/username/bluehostbackup/

It’s a good idea to schedule a cron job to run that command daily (or hourly if you change things quite often).

And that’s it. Making use of wp-db-backup and rsync you get an easy and fast backup solution that can save you a lot of trouble.

Schedule commands to run later on Linux and Mac

For scheduling periodical tasks you have Cron. But if you just want to schedule a command to run later you can use at.

# at 12:00
# at> echo “Scheduled phrase”|mail addr@provider.com
# at> (type control+d)
job 6 scheduled at 2009-06-16 12:00

You can see the scheduled tasks with atq and remove them with atrm

# atq
6 2009-06-16 12:00 a root
# atrm 6 (where 6 is the task id)

Mac4lin brings the beauty of the Mac to the Linux desktop

Seen on Lifehacker. Two years ago I bought a Macbook and from that moment on, I’m pretty much in love with the Mac look & feel. Its ease of use and integration are impressive. Mac4lin brings these fancy features to the Linux Desktop. It includes skins, wallpapers and interface refinements that resemble the Mac experience. It definitely worths a try!

mac4lin Mac4lin brings the beauty of the Mac to the Linux desktop