Advertisement
notbrain

simple lockfile mechanism with bash trap

Jan 24th, 2018
196
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. # simple script to test invoking over ssh and cancelling with ctrl-c to trigger trap cleanup
  4.  
  5. LOCKFILEPATH="/tmp/signaltest.lock"
  6.  
  7. function mutex() {
  8. if [ -f "$LOCKFILEPATH" ]; then
  9. echo -e "Build already in progress! Exiting.";
  10. exit 1;
  11. else
  12. touch $LOCKFILEPATH;
  13. trap cleanup EXIT SIGHUP SIGKILL SIGTERM SIGINT;
  14. fi
  15. }
  16.  
  17. function gitclone() {
  18. git clone --branch master git@github.com:bitcoin/bitcoin.git src_$(date +"%s");
  19. }
  20.  
  21. function cleanup() {
  22. rm -rf "$LOCKFILEPATH";
  23. }
  24.  
  25. mutex \
  26. && gitclone;
Advertisement
RAW Paste Data Copied
Advertisement