A question on csh/sh.

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Fri Nov 30 21:40:19 AEST 1990


In article <~0_^-Z^@rpi.edu> fitz at mml0.meche.rpi.edu (Brian Fitzgerald) writes:
> >password change. Basically I want to do:
> >	myshscript oldpasswd newpasswd
> IMHO, you might want to reconsider this idea for (at least) two reasons.

Yes, it's a bad idea, but the technical question still stands.

Quick 'n' easy, but a kludge:

   #!/bin/sh
   (sleep 5; echo $1; sleep 5; echo $2; sleep 5; echo $2) | pty passwd

Properly synchronized, using named pipes:

   #!/bin/sh
   /etc/mknod out.$$ p;exec 2>&1
   ( exec 4<out.$$; rm -f out.$$
   <&4 waitfor 'word: '
       echo $1
   <&4 waitfor 'word: '
       echo $2
   <&4 waitfor '(again): '
       echo $2
   ) | pty passwd > out.$$

Here waitfor is that same text search utility as last time:

   extern char *malloc(); main(argc,argv) int argc; char *argv[]; {
    int len; char *s; int pos; char ch; int f; int p; if (!argv[1])
    exit(1); len = strlen(argv[1]); if (!(s = malloc(len))) exit(2);
    pos = 0; f = 0; while (read(0,&ch,1) == 1) { if (write(2,&ch,1) != 1)
    exit(3); if (ch) { s[pos] = ch; pos++; if (pos == len) { f = 1;
    pos = 0; } if (f && (ch == argv[1][len - 1])) { for (p = 1;
    s[(pos + p) % len] == argv[1][p];p++) ; if (!argv[1][p]) exit(0);
    } } } exit(4); }

---Dan



More information about the Comp.unix.shell mailing list