Skip to content

Instantly share code, notes, and snippets.

@ypchen
Created September 4, 2017 05:02
Show Gist options
  • Save ypchen/a1a231baec95c0cc91c0fef8686c5d9a to your computer and use it in GitHub Desktop.
Save ypchen/a1a231baec95c0cc91c0fef8686c5d9a to your computer and use it in GitHub Desktop.
Watching names of files and directories & sending a Telegram message
# Usage: copy & paste in the bash cli
# toTelegram.bash is at https://gist.github.com/ypchen/66714ab493a645ac059fc7bd72aa4884
# Watch directly
WATCH_WORDS="WORDS_TO_WATCH"
SLEEP_SECS=120
while true; do
if [ "`ls | grep \"${WATCH_WORDS}\"`" == "" ]; then
echo Current watch result: `ls | grep "${WATCH_WORDS}"`
echo Keep watching... sleep for ${SLEEP_SECS} seconds
sleep ${SLEEP_SECS}
else
echo Current watch result: `ls | grep "${WATCH_WORDS}"`
echo Done and send TG
toTelegram.bash "Watching \"${WATCH_WORDS}\""
break
fi
done
# Watch by using tnit()
WATCH_WORDS="WORDS_TO_WATCH"
SLEEP_SECS=120
tnit "Watching \"${WATCH_WORDS}\"" "bash -ic \"while true; do
if \\\[ \\\"\\\`ls | grep \\\"${WATCH_WORDS}\\\"\\\`\\\" == \\\"\\\" \]; then
echo Current watch result: \\\`ls | grep \\\"${WATCH_WORDS}\\\"\\\`
echo Keep watching... sleep for ${SLEEP_SECS} seconds
sleep ${SLEEP_SECS}
else
echo Current watch result: \\\`ls | grep \\\"${WATCH_WORDS}\\\"\\\`
echo Done and send TG
break
fi
done\"" 18 ; date
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment