28 lines
550 B
Bash
28 lines
550 B
Bash
|
newfiles() {
|
||
|
|
||
|
# Path to watch. If the first parameter isn't set, just use /dev/
|
||
|
local path="${1:-/dev/}"
|
||
|
|
||
|
# Seconds without new events before exiting inotifywait
|
||
|
local timeout=10
|
||
|
|
||
|
printf "New files in %s:\n\n" "$path"
|
||
|
|
||
|
inotifywait \
|
||
|
--monitor \
|
||
|
--event create \
|
||
|
--timeout $timeout \
|
||
|
--format '%w%f' \
|
||
|
--quiet \
|
||
|
"$path"
|
||
|
|
||
|
local return=$?
|
||
|
if [[ $return == 2 ]]; then
|
||
|
printf "\nNo new events in %s seconds. Exiting.\n\n" $timeout
|
||
|
return 0
|
||
|
else
|
||
|
printf "\nE: inotifywait returned %s. Exiting.\n\n" $return
|
||
|
return $return
|
||
|
fi
|
||
|
}
|