Context
I am using this way of elevating permissions in a script if not run as a root.
My Bash script checks for the presence of a certain file it needs to use:
if [ $EUID != 0 ]; then
if [ -f "/foo/bar" ]
then
AGE=$(expr `date +%s` - `stat -c %Y "/foo/bar"`)
echo "/foo/bar is here, ${AGE}s old"
else
echo "/foo/bar not there (yet?)"
fi
sudo "$0" "$@"
exit $?
fi
# the rest of the script, needs /foo/bar
So if a non-root runs this, and there is the file, the response is like this /foo/bar is here, 27s old
. Otherwise, the response is /foo/bar is not there (yet?)
. Then, the sudo
prompt runs.
Now the question is: in the second case, when /foo/bar
is not ready yet, is there a way to notify the user once /foo/bar
appears? The user would type the password and see "oh the file is there" or "better wait before I hit Return".
There are two parts of this, detect a file has appeared in the file system (not asking about this one), and echo something while the sudo prompt is up.
Question
I am interested in the second part. Is it possible to write something to the output, above or below the sudo prompt, "asynchronously"?
inotify
to detect that the file has appeared.