mirror of https://github.com/tLDP/LDP
36 lines
756 B
Bash
36 lines
756 B
Bash
#!/bin/bash
|
|
|
|
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
|
|
|
|
if [ -z "$1" ]
|
|
then
|
|
echo "Usage: `basename $0` find-string"
|
|
exit $E_NOPARAMS
|
|
fi
|
|
|
|
|
|
echo "Updating 'locate' database..."
|
|
echo "This may take a while."
|
|
updatedb /usr & # Must be run as root.
|
|
|
|
wait
|
|
# Don't run the rest of the script until 'updatedb' finished.
|
|
# You want the database updated before looking up the file name.
|
|
|
|
locate $1
|
|
|
|
# Without the 'wait' command, in the worse case scenario,
|
|
#+ the script would exit while 'updatedb' was still running,
|
|
#+ leaving it as an orphan process.
|
|
|
|
exit 0
|