From b758f8bb41cd8ce44b531f2d05f2a5b4704a5d3c Mon Sep 17 00:00:00 2001 From: "Matteo Nastasi (mop)" Date: Thu, 18 Sep 2014 18:50:03 +0200 Subject: [PATCH] restarter.sh commodity added and reduced time of directories rename --- bin/restarter.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 bin/restarter.sh diff --git a/bin/restarter.sh b/bin/restarter.sh new file mode 100755 index 0000000..848c02c --- /dev/null +++ b/bin/restarter.sh @@ -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 + -- 2.17.1