Monitor folders using unix bash -


i need shell script monitor folders given in command , notify user if file created inside them (the name of file read keyboard).

i allowed use simple commands, not inotify... managed far:

#!/bin/bash     echo "please enter file want monitor: "     read file_monitor     #this infinite while     while [ 1 ] ;          #using test -e search file         test -e $file_monitor && echo "the file has been created!"         sleep 5     done 

i have find way stop while when file has been created, , search file in folders given in command line. can me, please?

to exit loop, use break:

test -e $file_monitor && echo "the file has been created!" && break 

i prefer break first, , echo after loop, or @mkemp6 suggested, directly use test condition loop.

to check folders, loop through them, , check file in each one.

break [n]        exit within for, while, until, or select loop.  if n   specified,  break  n        levels.   n  must   ≥  1.  if n greater number of enclosing loops,        enclosing loops exited. 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -