Sau khi đọc trả lời cho bài viết khác, tôi tìm thấy một bài (nay là đi), tôi tạo ra kịch bản này: -
#!/bin/bash
sha=0
previous_sha=0
update_sha()
{
sha=`ls -lR . | sha1sum`
}
build() {
## Build/make commands here
echo
echo "--> Monitor: Monitoring filesystem... (Press enter to force a build/update)"
}
changed() {
echo "--> Monitor: Files changed, Building..."
build
previous_sha=$sha
}
compare() {
update_sha
if [[ $sha != $previous_sha ]] ; then changed; fi
}
run() {
while true; do
compare
read -s -t 1 && (
echo "--> Monitor: Forced Update..."
build
)
done
}
echo "--> Monitor: Init..."
echo "--> Monitor: Monitoring filesystem... (Press enter to force a build/update)"
run
Nguồn
2011-02-10 16:54:52
thấy cũng http://stackoverflow.com/q/4060212/119790 –
cũng xem http://stackoverflow.com/q/880263/119790 –
Xem thêm http://superuser.com/questions/18151 7/how-to-execute-a-command-bất cứ khi nào-a-file-thay đổi –