Shell Scripting notes

November 7th, 2008

Eight years ago, back in 2000, I was decided to learn shell scripting. I found the Bourne Shell Programming book by Robert P. Sayle a very good way to start, so I began my way through it, reading the concepts, making the exercises and taking advantage the opportunity to write a sort of personal notes (in Spanish) using LyX (a text processor I liked very much at the moment).

Some time later I submitted the notes to the GPUL mailing list and they were posted at the research groups page. Unfortunately, there’s no way to access the notes from there, because a disk failure and the website revamping got them lost. It’s a pity, because not even the Internet Archive preserves a copy of them.

Those notes have a symbolic value for me. They served as a basis for later bash scripting courses I taught and, after many changes and adaptations, are still the main inspiration for the shell scripting slides used in the Caixanova Free Software Master.

For that reason, today I did a bit of computer archaeology and searched through my old backups until I found it. Now that this material is back, I want to share it with all of you:

Enjoy it!




Spanish version / versión en español:

Hace ocho años, allá por el 2000, me decidí a aprender shell scripting. Descubrí que el libro Bourne Shell Programming de Robert P. Sayle era una muy buena forma de empezar, así que inicié mi camino a través de él, leyendo los conceptos, haciendo ejercicios y aprovechando la oportunidad para escribir una especie notas personales (en español) usando LyX (un procesador de textos que me gustaba mucho en aquel momento).

Algún tiempo después envié las notas a la lista de correo de GPUL y fueron publicadas en la página de grupos de investigación. Por desgracia, no hay forma de acceder a las notas desde allí, porque un fallo de disco y la remodelación del sitio web hicieron que se perdieran. Es una pena, porque ni siquiera el Internet Archive guarda una copia de ellas.

Esas notas tienen un valor simbólico para mi. Sirvieron como base para cursos posteriores de scripting bash que impartí y, tras muchos cambios y adaptaciones, son aún la inspiración principal para las transparencias de shell scripting usadas en el Master de Software Libre de Caixanova.

Por esa razón, hoy hice un poco de arqueología informática y estuve buscando en mis viejos backups hasta que lo encontré. Ahora que este material ha reaparecido, quiero compartirlo con todos vosotros:

  • Notas sobre Shell Scripting (versión PDF): bash.pdf
  • Notas sobre Shell Scripting (archivo con versiones LyX, tex, ps y HTML): articulo_scripting.tgz

Disfrutadlo!

A new pet

November 3rd, 2008

Today I’ve received a brand new elePHPant. Will it survive in the hard ecosystem of my table? For the moment, it seems to be happy…

How to interact with an SVG image from an HTML document

November 3rd, 2008

Did you know that modern browsers already implement builtin support to visualize SVG drawings? And that you can make changes on them from the HTML document and make changes into the document from the SVG? In this post I’m going to explain all that through a simple example.

To create the SVG document you can use Inkscape. This program has a nice feature that allows you to edit attributes of particular nodes. For instance, you can select such a node, open the XML editor (Edit –> XML Editor…) and add a new attribute onclick to the node with the value:

javascript:window.parent.document.form1.bodypart.value='head';

When you’ve finished, just save the document as “plain SVG” to prevent compatibility problems.

Let’s go to the HTML part now. The easiest way to show the SVG in the document is by using an “embed” tag:

<html>
<body>

<h1>Anatomy of a smiley</h1>

<form name="form1">
Body part: <input type="text" name="bodypart" /> <br/>
</form>

<embed id="smiley" src="smiley.svg" width="745" height="1053" />

</body>
</html>

But that’s not enough. If you want to change SVG attributes using javascript, just add this code:

<script type="text/javascript">
   function changeColor(color) {
   var path=document.getElementById("smiley")
      .getSVGDocument()
      .getElementById("path2383");
   path.style.setProperty("fill",color, "");
   }
</script>

[...]

Color: <input type="text" name="color" value="#FFFF00" /> <br/>

<input type="button" value="Change color"
 onclick="javascript:changeColor(this.form.color.value);"/> <br/>

And that’s all. Now you have bidirectional knowledge between your HTML document and your SVG document. Take a look here to see the whole example.

There are still pending issues, like embedding the SVG code as part of the HTML source. That can be done including the proper DTDs and making sure that the document is interpreted as XHTML (that’s the most important think). Here is a modified version of the previous example to illustrate that, but I hadn’t been able to resolve nodes using this kind of embedded drawings.

Basic commands and scripting class at Free Software Master

October 26th, 2008

This weekend I’ve taught the first sessions at Caixanova Free Software Master. It consisted of a brief introduction to basic command line tools and some concepts about shell scripting and regular expressions tools.

All the course slides are licensed under a Creative Commons license. Until we finish to set up the course collaborative platform, the slides and exercises will be available in my personal web page. I’ll update this link when a final destination for those materials is found.

In addition, Ive compiled some interesting links related to the subject, which can be found in this dedicated Delicious section.

Slides of Master on Free Software

September 16th, 2008

A quick tip I’ve recalled today about: The slides written for all the subjects of the Free Software Master were released under a free license and are currently published. You can find them at this URL:

http://www.slideshare.net/tag/freeswmaster

A lot of useful information set free. Just have a look and… who knows, maybe you learn something new there.

Pam_preprofile 1.1, a swiss army knife for PAM

July 7th, 2008

Pam preprofile is a PAM module that ensures that some program or script is run each time a user logs into the computer. It’s suited for network administrators when they can’t rely on a particular shell to execute the user’s .profile, .bash_profile, .bashrc or similar… because sometimes the user home directory doesn’t even exist yet.

There are already many PAM modules out there, each one suited to a particular need (mounting shares, creating tmp dirs, etc.), but the real advantage of pam_preprofile is its versatility. Pam_preprofile can be used to satisfy any need not being implemented by any existing PAM module at this time but which can be written as a script by the system admin.

The configuration is simple. Just install the module at /lib/security/ and add this line at the end of /etc/pam.d/common-session:

session required pam_preprofile.so /tmp/myprogram.sh /usr/doc

That will call /tmp/myprogram.sh every time the user starts a session (logs into the desktop), passing it a “/usr/doc” parameter, plus an extra parameter with the username being authenticated.

In the previous version of the module, the script was executed always at the session stage. It was very helpful to create the user account. But some weeks ago, a network administrator presented me a scenario where he needed to execute the script each time the system asked the user for a password (that is, at “auth” stage), because the user info could have been updated meanwhile and some local configuration should be updated based on that.

I then improved the module and the new 1.1 version is out. It allow scripts to be executed in the PAM stage you want (account, auth, password and session), not only at the “session” stage allowed by the previous version.

Are you a network administrator? You can download it from:

http://community.igalia.com/twiki/bin/view/Corunix/ProjectDownloadStable

I’ve a landline phone number in USA

July 4th, 2008

I know, I know… having a landline phone number in USA isn’t uncommon if you live there. But the fact is that I don’t live there.

The phone number is offered for free by IpKall and it’s binded to my Gizmo SIP account (VoIP). That way, when you call that number, and if I’m logged into my Gizmo account, I can receive your call. Moreover, if you’ve a Skype account it should be cheap for you to call me. Yes, you’ve catched it: it’s the perfect and cheap (but not free) SIP-Skype bridge.

In fact, I’m thinking to bind the number to the SIP account of the PolyCom we’ve in the office. That way, we could set up a multiconference among some Skype users and the PolyCom.

P.S.: I’m not showing here the real phone number nor the Gizmo account for privacy reasons. If you’d like to know them, just contact me.

A safe upgrade to Diablo

June 25th, 2008

At the end, Maemo Diablo release for N810 is out. But if you have valuable information, programs or configuration on it maybe you’re worried about what you’ll loose in a reflashing. In fact, if you’ve done the upgrade yet you’ll notice that the main part of the apps from Extras repository are missing in Diablo for the moment. Fortunately, there’s a way to install the apps from the old Chinook repository.

Here are six simple steps to perform the upgrade process and restore all your current applications:

  1. Backup your /home/user to a safe place by hand. Standard backup tool won’t
    backup every file you’ve at home and maybe you could need them later…
  2. Do a backup using the backup tool.
  3. Reflash the device with the new image using the flasher tool according to the reflashing instructions
  4. Restore the backup. Some old apps will remain grayshaded because the backup
    tool can’t find them in the now current Diablo repository.
  5. Open Application Manager. Menu, tools, application catalog. Maemo Extras,
    edit. Distribution: chinook, uncheck the “disabled” checkbox, Accept. Close.
  6. Menu, tools, restore applications. Accept.

That’s all. Enjoy your updated device!

How to send SMS in Linux using Skype

May 29th, 2008

Skype for Linux doesn’t support SMS sending from the user interface. But that functionality is in fact implemented in the library and external apps can use it via the public API. I’ve found a working example of that nice feature. Just do these simple steps:

  1. Download Skype4Py from here, uncompress it and install it typing sudo python setup.py install
  2. Download Skype tools 0.11 from here and uncompress it
  3. Open your Skype client and prepare for the authorization dialog that will appear when you execute the next step
  4. Enter into the previous directory and send the SMS: ./send_sms.py +34123123456 My test sms

If the message takes too much to be sent, stop the app (CTRL+C), delete the authorization using the Skype options dialog, and try again. Third and next times worked fine for me.

Shishen Sho Mahjongg 0.3 released

May 26th, 2008

Version 0.3 of Shishen Sho Mahjongg has just been released. The main improvements since 0.2 are: Gravity, hints, undo history, time counter and speed improvements.

You can download the game and know more about it visiting the project page at Maemo Garage.

Enjoy it!

Click here to install this application

28/05/2008 UPDATE: Now the application is also available in Maemo Extras repository and listed in Maemo Downloads with its own green “click to install” icon :-)