Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!rlgvax!cvl!umcp-cs!fred From: fred@umcp-cs.UUCP Newsgroups: net.sources Subject: Shell script to generate shell script which recreates /dev/* Message-ID: <7567@umcp-cs.UUCP> Date: Wed, 20-Jun-84 17:32:00 EDT Article-I.D.: umcp-cs.7567 Posted: Wed Jun 20 17:32:00 1984 Date-Received: Fri, 22-Jun-84 11:06:24 EDT Distribution: net Organization: Univ. of Maryland, Computer Science Dept. Lines: 58 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 }'