forked from lgollut/meteor-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_on_save.sh
executable file
·37 lines (31 loc) · 1.04 KB
/
run_on_save.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
#
function usage() {
echo -e "USAGE :: ${0} <file_to_watch> <command_to_execute> <parm_1> <parm_2> <parm_n>";
}
if [[ "X$1X" = "XX" ]]; then
usage;
exit 1;
fi;
if [[ "X$2X" = "XX" ]]; then
usage;
exit 1;
fi;
WATCHED_FILE="$1" # Name of file
THE_COMMAND_TO_RUN="${*:2}" # Command to run on change (takes rest of line)
# PREVIOUS_SAVE_TIME="$(ls --full-time ${WATCHED_FILE} | awk '{ print $7 }')" # Get latest save time
PREVIOUS_MD5=$(md5sum ${WATCHED_FILE} | cut -d " " -f 1); # Get latest message digest
echo ">${PREVIOUS_MD5}<";
declare DEFDIR=$(pwd);
while true
do
# LATEST_SAVE_TIME="$(ls --full-time ${WATCHED_FILE} | awk '{ print $7 }')" # Compare to new save time
# if [ "$PREVIOUS_SAVE_TIME" != "${LATEST_SAVE_TIME}" ]; then
LATEST_MD5=$(md5sum ${WATCHED_FILE} | cut -d " " -f 1); # Compare to new message digest
if [ "$PREVIOUS_MD5" != "${LATEST_MD5}" ]; then
# echo " Do ${DEFDIR}/${THE_COMMAND_TO_RUN}";
PREVIOUS_MD5="${LATEST_MD5}";
${THE_COMMAND_TO_RUN};
fi; # If different, run command
sleep 1;
done;