Some small tools for shell.
- Locker
- WFC (Workflow controller)
Use "dot" to include utility.sh in your custom script.
. utility.sh
Use locker to avoid cronjob conflict. See example:
test.sh:
#!/bin/bash
lock_it
echo "Start testing"
sleep 1h
echo "End testing"
unlock_it
Result:
$ bash test.sh
Successfully lock: test.sh.lock
$ bash test.sh
Previous process exists! can't acquire lock!
This tool provides convenient to control workflow for bash. While we want to execute some dependent jobs, we need some mechanism to check result of each jobs. Like:
$command1
if [ "$?" -ne 0 ]; then # Check result of command1
...
$command2
fi
It shows a lot of redundant scope in code. We can save this duplicated script by simple function likes below. It also automatically records all execution results into log.
Revised version with wfc tool:
wfc "$command1"
wfc "$command2" # If it gets an incorrect result in command1, then command2 will not be executed.
BSD License