Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Use it for finding the total CPU time taken by tasks on Hadoop, after making the change.
#!/bin/bash
LOGS_PATH="logs/userlogs/"
declare JOB=`ls $LOGS_PATH`;
JOB_PATH="$LOGS_PATH$JOB";
COMMAND="ls -1 --hide=job* $JOB_PATH/";
declare RET=`$COMMAND`;
`rm cputime.out`;
`touch cputime.out`;
for TASK in $RET
do
FILE="$JOB_PATH/$TASK/stderr";
`cat $FILE >> cputime.out`;
done;
declare TIME=`cat cputime.out | grep -o -E "(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)?user"`;
EXPR="0.0";
for T in $TIME
do
EXPR="$EXPR+${T/user/}";
done;
declare RES=`echo "$EXPR" | bc`;
echo "CPU Time taken by Job $JOB: $RES";
echo "Please do 'rm -rf logs/userlogs' before you run another job";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment