Messing with Expect
Mar. 16th, 2010 09:44 pmPrompted by a couple of minor system irritations, I've spent a few odd moments this week brushing up my Expect and TCL skills in order to automate some tedious interactive tasks. And this has has led to a couple of minor revelations.
I've found that although TCL still isn't my favourite programming language, I've found myself disliking it less the more I use it and the more I come to grips with its quirks. Which is no bad thing, given that it is used by environment modules.
I've also realised that the main trick to writing robust Expect scripts is to expect shell prompts before and after each command. So before every command, it is worth sending a blank line to the child process and expecting a prompt to ensure that the previous command has completed successfully; and after each command, after expecting for a string that indicates whether the command has succeeded or failed, it is worth waiting for the child process to return a prompt in order to ensure that the most recent command really has finished.
I've also discovered that it is possible to reset user passwords on AIX without marking them as expired. This can be achieved by running the command
Although I'm not sure that I'll ever use Expect for much more than automating user account creations — not something that usually falls within my remit — it's still nice to be able to automate away at least some of the tedium.
I've found that although TCL still isn't my favourite programming language, I've found myself disliking it less the more I use it and the more I come to grips with its quirks. Which is no bad thing, given that it is used by environment modules.
I've also realised that the main trick to writing robust Expect scripts is to expect shell prompts before and after each command. So before every command, it is worth sending a blank line to the child process and expecting a prompt to ensure that the previous command has completed successfully; and after each command, after expecting for a string that indicates whether the command has succeeded or failed, it is worth waiting for the child process to return a prompt in order to ensure that the most recent command really has finished.
I've also discovered that it is possible to reset user passwords on AIX without marking them as expired. This can be achieved by running the command
pwdadm -c <user> against the account. The opposite, marking a password as expired without changing the user's password, can be achieved by running pwdadm -f ADMCHG <user>.Although I'm not sure that I'll ever use Expect for much more than automating user account creations — not something that usually falls within my remit — it's still nice to be able to automate away at least some of the tedium.