Литмир - Электронная Библиотека
Содержание  
A
A

  if (isascii(c) &&

   (isprint(c) || c=='\n' || c=='\t' || c==' '))

   putchar(c);

  else if (!strip)

   printf("\\%03o", с);

}

3.8.61

waitfile.c

/* waitfile: wait until file stops changing */

#include <stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

char *progname;

main(argc, argv)

 int argc;

 char *argv[];

{

 int fd;

 struct stat stbuf;

 time_t old_time = 0;

 progname = argv[0];

 if (argc < 2)

  error("Usage: %s filename [cmd]", progname);

 if ((fd = open(argv[1], 0)) == -1)

  error("can't open %s", argv[1]);

 fstat(fd, &stbuf);

 while (stbuf.st_mtime != old_time) {

  old_time = stbuf.st_mtime;

  sleep(60);

  fstat(fd, &stbuf);

 }

 if (argc == 2) { /* copy file */

  execlp("cat", "cat", argv[1], (char*)0);

  error("can't execute cat %s", argv[1]);

 } else { /* run process */

  execvp(argv[2], &argv[2]);

  error("can't execute %s", argv[2]);

 }

 exit(0);

}

#include "error.c"

3.8.62

watchfor

# watchfor: watch for someone to log in

PATH=/bin:/usr/bin

case $# in

0) echo 'Usage: watchfor person' 1>&2; exit 1

esac

until who | egrep "$1"

do

 sleep 60

done

3.8.63

watchwho

# watchwho: watch who logs in and out

PATH=/bin:/usr/bin

new=/tmp/wwho1.$$

old=/tmp/wwho2.$$

> $old # create an empty file

while : # loop forever

do

 who >$new

 diff $old $new

 mv $new $old

 sleep 60

done | awk '/>/ { $1 = "in: "; print }

            /</ { $1 = "out: "; print }'

3.8.64

which1

# which cmd: which cmd in PATH is executed, version 1

case $# in

0) echo 'Usage: which command' 1>&2; exit 2

esac

for i in `echo $PATH | sed 's/^:/.:/

                            s/::/:.:/g

                            s/:$/:./

                            s/:/ /g'`

do

 if test -f $i/$1 # use test -x if you can

 then

  echo $i/$1

  exit 0 # found it

 fi

done

exit 1 # not found

3.8.65

which1.H

# which cmd: which cmd in PATH is executed, version 1

case $# in

0) echo 'Usage: which command' 1>&2; exit 2

esac

for i in `echo $PATH | sed 's/^:/.:/

                            s/::/:.:/g

                            s/:$/:./

                            s/:/ /g'`

do

 if test -f $i/$1 # use test -x if you can

 then

  echo $i/$1

  exit 0 # found it

 fi

done

exit 1 # not found

@@@ Fri Oct 14 14:21:11 EDT 1983 original version

3.8.66

which2

# which cmd: which cmd in PATH is executed, final version

186
{"b":"248117","o":1}