shell scripts smalltalk

Mail scripting

I recommend you browse the NetClients package to see methods to show POP mail attributes, e.g. sender, destination, content.

POP mail snippet

   PackageLoader fileInPackage: 'NetClients'.
   popHost     := 'ourPOPHost.com'.
   popUsername := 'popUser'.
   popPassword := 'POPpassword'.
   client := NetClients.POP.POPClient connectToHost: popHost.
   [client
       username: popUsername
       password: popPassword.
       client login.
       client
           getNewMailMessages: [:mimeEntity |
           | subject from |

Scripts - file and folder enumeration

And here's one to navigate through a home directory folder and change ownership of all folders to the home directory owner.

This script was required after the home directories got copied onto another server with a different operating system.

This works in Smalltalk 3.0x (I understand there are changes coming in File/Directory in 3.1)

<pre>

#! /usr/local/bin/gst  -f


Object subclass: #DirNav
       instanceVariableNames: ''
       classVariableNames: ''
       poolDictionaries: ''
       category: 'SG-Scripting'!

DirNav comment:

Scripting example - regular expressions and Dictionaries

And here's another one with some regular expression comparisons.

The occasion being a requirement to link some OS X mailservers together. Unfortunately Apple didn't compile LDAP into Postfix so we're using output from the Apple Directory to generate text files for inter-branch mail routing.

<pre>
  1. !/usr/local/bin/gst -f

"read a text file with LDIF records and generate a Postfix virtuals file

 from the records.
 Require uid and keyword attributes.
  - uid is home directory shortname and mail aliases e.g. jim, jim.bob

Beginner scripting

I've begun using GNU Smalltalk for scripting purposes. The more I use it, the more I like it. Scripts pass the "its six months later can I understand what I did here" test easily, and errors usually result in a stack trace or a line number so debugging is fine.

Anyway, as always with a new language it takes a little while to figure out how to read and write files, how to display integers etc. Like most people, I find examples are helpful.

Syndicate content

User login