Ian*_*han 17 linux bash automation rspec build
我想在文件发生变化时自动启动构建.
我在Ruby中使用过autospec(RSpec)并喜欢它.
怎么能在bash中完成?
在阅读其他帖子的回复后,我发现了一个帖子(现在已经不见了),我创建了这个脚本: -
#!/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
Run Code Online (Sandbox Code Playgroud)
这个脚本怎么样?使用'stat'命令获取文件的访问时间,并在访问时间发生变化时(无论何时访问文件)运行命令.
#!/bin/bash
while true
do
ATIME=`stat -c %Z /path/to/the/file.txt`
if [[ "$ATIME" != "$LTIME" ]]
then
echo "RUN COMMNAD"
LTIME=$ATIME
fi
sleep 5
done
Run Code Online (Sandbox Code Playgroud)