Shell script to generate shell script which recreates /dev/*

fred at umcp-cs.UUCP fred at umcp-cs.UUCP
Thu Jun 21 07:32:00 AEST 1984


Have you ever accidentally trashed your entire /dev directory? You
have?  Well how did you decide which devices to re-create using
mknod?  Sort of a bother looking all that up and typing in all the
commands by hand wasn't it?  Here's a shell script which makes the
whole process trivial. Just run it late at night and it'll keep
around a shell script which will do the proper sequence of mknods
chowns and chmods to recreate the directory. We use the crontab
line:

	10 4 * * * /usr/lib/make_dev > /etc/rebuild_dev

To automatically keep /etc/rebuild_dev current. If the /dev directory
gets seriously trashed, we just have to execute the script
/etc/rebuild_dev (as super-user) to restore things to a reasonable
state.

:::::::::::::::::
/usr/lib/make_dev
:::::::::::::::::
|#! /bin/sh
|#
|# @(#)make_dev.sh	(U of Maryland) FLB 10-Feb-1983
|#
|# This shell script outputs a shell script which will rebuild /dev
|#
|echo '#! /bin/sh'
|echo '#'
|echo -n '# rebuild /dev as of '
|date
|echo '#'
|#
|# Do a ``mknod'' for each device.
|#
|ls -l  /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk '/^[bc]/ { print "/etc/mknod " $9 " " substr($1, 1, 1) " " \
|		$4 " " $5 }'
|#
|# Change user and group ownerships.
|#
|ls -l  /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk '/^[bc]/ { print "/etc/chown " $3 " " $9; }'
|ls -lg /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk '/^[bc]/ { print "/etc/chgrp " $3 " " $9; }'
|#
|# Change file mode.
|#
|ls -l  /dev | /usr/bin/sed 's/,/ /' | \
|	/usr/bin/awk 'BEGIN { x["r"] = 4; x["w"] = 2; x["x"] = 1 }
|		/^[bc]/ { a =   x[substr($1, 2, 1)]; \
|			a = a + x[substr($1, 3, 1)]; \
|			a = a + x[substr($1, 4, 1)]; \
|			b =     x[substr($1, 5, 1)]; \
|			b = b + x[substr($1, 6, 1)]; \
|			b = b + x[substr($1, 7, 1)]; \
|			c =     x[substr($1, 8, 1)]; \
|			c = c + x[substr($1, 9, 1)]; \
|			c = c + x[substr($1, 10, 1)]; \
|			print "/bin/chmod " a b c " " $9 }'



More information about the Comp.sources.unix mailing list