restarter.sh commodity added and reduced time of directories rename
authorMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Thu, 18 Sep 2014 16:50:03 +0000 (18:50 +0200)
committerMatteo Nastasi (mop) <nastasi@alternativeoutput.it>
Thu, 18 Sep 2014 16:50:03 +0000 (18:50 +0200)
bin/restarter.sh [new file with mode: 0755]

diff --git a/bin/restarter.sh b/bin/restarter.sh
new file mode 100755 (executable)
index 0000000..848c02c
--- /dev/null
@@ -0,0 +1,39 @@
+#!/bin/bash
+# set -x
+cd "$PWD" 2>/dev/null
+dirnm="$PWD"
+cwd_old="$(ls -i -d "$dirnm" | cut -d ' ' -f 1)"
+pid_exe=""
+while true; do
+    if [ "$pid_exe" = "" ]; then
+        sleep 2
+        cd "$dirnm" 2>/dev/null
+        "$@" &
+        pid_exe="$!"
+    fi
+    sleep 1
+    kill -0 $pid_exe >/dev/null 2>&1
+    if [ $? -ne 0 ]; then
+       echo "Process not present"
+       exit 0
+    fi
+    for tloop in 1 2 3 4 5; do
+        cwd_cur="$(ls -i -d "$dirnm"  2>/dev/null | cut -d ' ' -f 1)"
+        if [ "$cwd_cur" ]; then
+            break
+        fi
+        sleep 1
+    done
+    if [ $tloop -eq 5 ]; then
+        echo "Unavailable current working directory"
+       exit 1
+    fi  
+    if [ "$cwd_cur" != "$cwd_old" ]; then
+       kill $pid_exe
+       wait $pid_exe
+        echo "WAIT EXIT: $?"
+        pid_exe=""
+    fi
+    cwd_old="$cwd_cur"
+done
+