ghosttownenjoyer👻🌃@lemmy.ml to Linux Questions@lemmy.zipEnglish · edit-25 months agoRun a shell script whenever a file in a certain directory changes?message-squaremessage-square4linkfedilinkarrow-up11file-text
arrow-up11message-squareRun a shell script whenever a file in a certain directory changes?ghosttownenjoyer👻🌃@lemmy.ml to Linux Questions@lemmy.zipEnglish · edit-25 months agomessage-square4linkfedilinkfile-text
Using a shell script, can I watch a folder and block program execution until a file in a certain folder changes?
minus-squarerunning_ragged@lemmy.worldlinkfedilinkEnglisharrow-up0·5 months agoCan continuously loop over the file, examine the md5 hash for changes. Run the script if it has changed. https://stackoverflow.com/questions/6475252/bash-script-watch-folder-execute-command daemon() { chsum1="" while [[ true ]] do chsum2=`find src/ -type f -exec md5 {} \;` if [[ $chsum1 != $chsum2 ]] ; then if [ -n "$chsum1" ]; then compile fi chsum1=$chsum2 fi sleep 2 done }
minus-squarehperrin@lemmy.calinkfedilinkEnglisharrow-up1·5 months agoOh god please don’t do this. Constantly reading the file is just stressing your IO for no reason. Please inotify instead: https://linux.die.net/man/1/inotifywait
minus-squareghosttownenjoyer👻🌃@lemmy.mlOPlinkfedilinkEnglisharrow-up0·5 months agoI really like this, replace compile with whatever command you desire I guess.
minus-squarehperrin@lemmy.calinkfedilinkEnglisharrow-up1·5 months agoThis is a terrible solution. You will stress your IO for no reason.
Can continuously loop over the file, examine the md5 hash for changes.
Run the script if it has changed.
https://stackoverflow.com/questions/6475252/bash-script-watch-folder-execute-command
Oh god please don’t do this. Constantly reading the file is just stressing your IO for no reason.
Please inotify instead:
https://linux.die.net/man/1/inotifywait
I really like this, replace compile with whatever command you desire I guess.
This is a terrible solution. You will stress your IO for no reason.