On Tue, Oct 05, 2004 at 12:41:59PM -0400, Kripa Sundar wrote:
> Dear Gyepi,
> 
> > Along a similar vein, I frequently generate sh code from perl rather than
> > simply make 'system()/qx/``' calls from perl. Though there are several benefits to
> > this approach, the most compelling, for me, is the ability to embed 'undo'
> > statements in the generated code so the shell code can, given an 'undo'
> > invocation, rollback the previous run. [...]
> 
> What is an 'undo' statement?
> What does "the previous run" mean?
> What does "rollback the previous run" mean?

Here's an example:

My last use of this technique involved a situation where I needed to read a bunch of 
text files
containing user information and add the users to /etc/passwd file, add them to various
groups, create their home directories, and add entries to a samba passwd
database, etc, and I wanted all of those operations to have atomicity:
that is succeed completely or fail completely. My perl script read the text
files and a generated a shell script like this:

  #!/bin/sh
  type=$1

  if [ "$type" eq "do" ]; then
    groupadd bar
    useradd foo ...
    gpasswd -a foo bar
    ...

  elif [ "$type" eq "undo" ]; then
    userdel foo
    groupdel bar
    ...
  fi

except there were more users and more actions.

The script could then be invoked as

  ./script do

or

  ./script undo


so if a script invocation with a 'do' argument failed for whatever reason, I could 
invoke the script
with an 'undo' argument to restore the system to its previous state.

I hope that makes it clearer.

-Gyepi
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to