Tag Archives: GNU

Using expect

Let’s give a brief intro to expect. Basically is a tool for automating interactive applications such as FTP, telnet, ssh and similar. Expect has regular expression pattern matching and general program capabilities.

Let’s start installing Expect. Type in your Debian based box:

sudo aptitude install expect

That’s it. You are done.

Now lets write a simple ssh expect script. Substitute user, password and hostname for the user, password and hostname to the machine you want to log into.

#!/usr/bin/expect
spawn ssh user@hostname
expect “user@hostname’s password:”
send “password\r”
expect “$\r”
send “who; pwd; last | head\r”
expect “$\r”
send “date; exit\r”
expect eof

The script is pretty simple. It basically logs into a box and executes date, pwd, who and last commands. But it clearly shows the power of expect for automating tasks.

More info at Wikipedia and Expect homepage.

Apache mod ReWrite in Debian

Installing apache on a Debian server is quite easy. Just type:

sudo aptitude install apache2

But the previous command misses an important Apache module. The ModRewrite module. How do we install this module? There are two ways, the easy and the hard way. Lets explain the easy way first. Type:

sudo a2enmod rewrite && sudo /etc/init.d/apache2 restart

That’s it. Module installed and ready to go. Lets explain the hard way now.

sudo find /usr/lib -type f -name “mod_rewrite.so”

sudo vim /etc/apache2/mods-enabled/rewrite.load

Write the where the rewrite module is located, probably:

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

And finally:

sudo /etc/init.d/apache2 restart

Here is a small intro on how to use this module.

Enjoy.