Skip to content

Commit

Permalink
Improvements on output format
Browse files Browse the repository at this point in the history
  • Loading branch information
nfaguirrec committed Dec 10, 2015
1 parent fe794a3 commit b1fd7e7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 28 deletions.
25 changes: 16 additions & 9 deletions sjobq.d
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,15 @@ function start()
##
function stop()
{
local id=""

# @todo Maybe STOP_FILE it is not still necessary
echo "" > $STOP_FILE
sleep 3
sleep $REFRESH_INTERVAL

# @todo It's neccessary to catch the output of kill command to avoid the message Killed
id="`ps -u $USER | grep "sjobq.d$" | awk '{print $1}'`"
kill -s SIGKILL $id &> /dev/null
rm -rf $DATA_DIR
}

Expand Down Expand Up @@ -215,7 +222,7 @@ function main()
then
# It's already running.
echo "### Error ### The daemon sjobq.d is already running"
echo " stop it using \"sjobq.d stop\""
echo " You might want to run \"sjobq.d stop\" to stop it."
exit 1
fi
#------------------------------------
Expand All @@ -227,21 +234,21 @@ function main()

nohup $0 __start > $DATA_DIR/log 2> $DATA_DIR/err &

echo "=============================="
echo "==============================="
echo " SJobQ daemon has been started"
echo "=============================="
echo "==============================="
;;
stop)
isRunning="`ps -u $USER | grep "sjobq.d$" | awk '{a[NR]=$1}END{ if(a[2]==(a[1]+1)) print 0; else print 1}'`"
if [ $isRunning -eq "0" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
echo " You might want to run \"sjobq.d start\" to correct this."
exit 1
else
echo "=============================="
echo "==============================="
echo " SJobQ daemon has been stopped"
echo "=============================="
echo "==============================="
stop
fi

Expand All @@ -262,9 +269,9 @@ function main()

nohup $0 __start > $DATA_DIR/log 2> $DATA_DIR/err &

echo "================================"
echo "================================="
echo " SJobQ daemon has been restarted"
echo "================================"
echo "================================="
;;
__start)
start
Expand Down
62 changes: 46 additions & 16 deletions sjobq.del
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function showJobs()
echo ""
echo "pid = `cat $CURRENT_JOB_HOME/pid`"
echo "command = `cat $CURRENT_JOB_HOME/com`"
echo "dir = `cat $CURRENT_JOB_HOME/pwd`"
echo "dir = `cat $CURRENT_JOB_HOME/pwd | sed 's/\/home\/'$USER'\//~\//g'`"
echo "time spent = `diffTime $beginTime $endTime`"
echo "pids = `cat $CURRENT_JOB_HOME/pids`"
echo "tree ="
Expand All @@ -86,33 +86,55 @@ function showJobs()

if [ -n "$ID_LIST" ]
then
maxCharInDirColumn=0
for procID in $ID_LIST
do
nCharInDir=`cat $DATA_DIR/$procID.pwd | sed 's/\/home\/'$USER'\//~\//g' | wc -c`
if [ "$maxCharInDirColumn" -lt "$nCharInDir" ]; then maxCharInDirColumn=$nCharInDir; fi
done
if [ "$maxCharInDirColumn" -lt 20 ]; then maxCharInDirColumn=20; fi

rowSeparator=`echo -n "+-------+"`
rowSeparator=$rowSeparator`echo "-" | awk '{for(i=0;i<='$maxCharInDirColumn';i++) printf($1)}'`
rowSeparator=$rowSeparator`echo "+--------------------"`

printf "%s\n" "+-------+"
echo "| QUEUE |"
printf "%s\n" "+-------+-------------------------------------------+----------"
printf "|%6s |%42s | %s\n" "id" "directory" "command"
printf "|%6s |%42s | %s\n" "" "" ""
echo $rowSeparator
printf "|%6s |%"$maxCharInDirColumn"s | %s\n" "id" "directory" "command"
printf "|%6s |%"$maxCharInDirColumn"s | %s\n" "" "" ""
for procID in $ID_LIST
do
id=`cat $DATA_DIR/$procID.bid`
dir=`cat $DATA_DIR/$procID.pwd | sed 's/\/home\/'$USER'\//~\//g'`
command=`cat $DATA_DIR/$procID.com`

printf "|%6s |%42s | " $id $dir
printf "|%6s |%"$maxCharInDirColumn"s | " $id $dir
echo $command
done

printf "%s\n" "+-------+-------------------------------------------+----------"
echo $rowSeparator
fi
echo ""

if [ -f "$DATA_DIR/history" ]
then
maxCharInDirColumn=`tail -n $(( 4*$MAX_HISTORY )) $DATA_DIR/history \
| grep -E "dir\s+=" \
| sed 's/\/home\/'$USER'\//~\//g' \
| sed -r 's/dir\s+=//g' \
| gawk '(length(line)<length($0)){line=$0}END{print line}' | wc -c`

rowSeparator=`echo -n "+-------------+"`
rowSeparator=$rowSeparator`echo "-" | awk '{for(i=0;i<'$maxCharInDirColumn';i++) printf($1)}'`
rowSeparator=$rowSeparator`echo "+--------------------"`

printf "%s\n" "+-------------+"
echo "| HISTORY |"
printf "%s\n" "+-------------+-------------------------------------------+----------"
printf "|%12s |%42s | %s\n" "time spent" "directory" "command"
printf "|%12s |%42s | %s\n" "" "" ""
cat $DATA_DIR/history | tail -n $(( 4*$MAX_HISTORY )) | sed 's/\/home\/'$USER'\//~\//g' | \
echo $rowSeparator
printf "|%12s |%"$maxCharInDirColumn"s| %s\n" "time spent" "directory " "command"
printf "|%12s |%"$maxCharInDirColumn"s| %s\n" "" "" ""
tail -n $(( 4*$MAX_HISTORY )) $DATA_DIR/history | sed 's/\/home\/'$USER'\//~\//g' | \
awk '
BEGIN{
n=0
Expand All @@ -121,24 +143,25 @@ function showJobs()
($1=="time"){
timeSpent = sprintf("%12s",$4)
line[n] = "|"timeSpent" | "dir" | "command
line[n] = "|"timeSpent" |"dir" | "command
n+=1
}
($1=="dir"){
dir = sprintf("%41s",$3)
dir = sprintf("%'$(($maxCharInDirColumn-1))'s",$3)
}
($1=="command"){
command = sprintf("%s",$3)
gsub("command[[:blank:]]+=[[:blank:]]+", "")
command = sprintf("%s",$0)
}
END{
for(i=0;i<n;i++)
print line[i]
}'

printf "%s\n\n" "+-------------+-------------------------------------------+----------"
echo $rowSeparator
fi
}

Expand Down Expand Up @@ -197,7 +220,14 @@ function main()
if [ -z "`ps -u $USER | grep "sjobq.d$"`" ]
then
echo "### Error ### The daemon sjobq.d is not running"
echo " run it using \"sjobq.d start\""
echo " You might want to run \"sjobq.d start\" to correct this."
exit 1
fi

if [ ! -d "$DATA_DIR" ]
then
echo "### Error ### Data directory $DATA_DIR is empty"
echo " You might want to run \"sjobq.d restart\" to correct this."
exit 1
fi

Expand All @@ -212,4 +242,4 @@ function main()
fi
}

main $*
main $*
6 changes: 3 additions & 3 deletions sjobq.push
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ function main()

if [ $previous -eq "32767" ]
then
BID="0"
BID="1"
else
BID=$(( $previous + 1 ))
fi

else
echo "0" > $COUNTER_FILE
echo "1" > $COUNTER_FILE
BID=`cat $COUNTER_FILE`
fi
echo $BID > $COUNTER_FILE
Expand All @@ -56,7 +56,7 @@ function main()

echo "id = $BID"
echo "command = $COMMAND"
echo "dir = $PWD"
echo "dir = `echo $PWD | sed 's/\/home\/'$USER'\//~\//g'`"

echo "$BID" > $DATA_DIR/$BID.bid
echo "$COMMAND" > $DATA_DIR/$BID.com
Expand Down

0 comments on commit b1fd7e7

Please sign in to comment.