LDP/LDP/guide/docbook/abs-guide/ex39.sh

36 lines
756 B
Bash
Raw Normal View History

2001-07-10 14:25:50 +00:00
#!/bin/bash
2001-09-04 13:27:31 +00:00
ROOT_UID=0 # Only users with $UID 0 have root privileges.
E_NOTROOT=65
E_NOPARAMS=66
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "Must be root to run this script."
# "Run along kid, it's past your bedtime."
exit $E_NOTROOT
fi
2001-07-10 14:25:50 +00:00
if [ -z "$1" ]
then
echo "Usage: `basename $0` find-string"
2001-09-04 13:27:31 +00:00
exit $E_NOPARAMS
2001-07-10 14:25:50 +00:00
fi
2001-09-04 13:27:31 +00:00
2001-07-10 14:25:50 +00:00
echo "Updating 'locate' database..."
echo "This may take a while."
updatedb /usr & # Must be run as root.
2001-07-10 14:25:50 +00:00
wait
# Don't run the rest of the script until 'updatedb' finished.
2016-10-24 12:36:27 +00:00
# You want the database updated before looking up the file name.
2001-07-10 14:25:50 +00:00
locate $1
2005-05-08 20:09:31 +00:00
# Without the 'wait' command, in the worse case scenario,
#+ the script would exit while 'updatedb' was still running,
#+ leaving it as an orphan process.
2001-07-10 14:25:50 +00:00
exit 0