source $HOME/.bashrc

#!/bin/bash
#
# This script will cut the length of sequences within a fastq file

if [ x"$1" == x ]; then

        echo "please specify .nextflow.log path"

        exit 1

fi

if [ x"$2" == x ]; then

        echo "please specify cluster user to be checked"

        exit 1

fi

CWD="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
RES=$CWD"/pipe_res.txt"
LOG=$1
USER=$2

date > $RES
echo "************   CLUSTER JOBS   ***************" >> $RES
echo "Jobs submitted by ${USER} (qw = pending, r = running, Eqw = error)" >> $RES
qstat -u "$USER" | grep 'nf-' | awk '{print $5}'| sort | uniq -c >> $RES
qstat -u "$USER" | grep 'nf-' | awk '{if ($5=="r") print $3}'| sort| uniq -c >> $RES
echo "************   NEXTFLOW CACHED   ***************" >> $RES
grep Cached $LOG | sort | uniq | cut -d" " -f14 | sort | uniq -c >> $RES
echo "***********   NEXTFLOW COMPLETED   *************" >> $RES
grep COMPLETED $LOG | grep "exit: 0" | sort | uniq | cut -d" " -f16 | sort | uniq -c >> $RES
echo "*************   NEXTFLOW FAILED   **************" >> $RES
grep NOTE $LOG | sort | uniq | cut -d" " -f12| sed s/\`//g| sort|uniq -c >> $RES
echo "**********   NEXTFLOW RESUBMITTED   ************" >> $RES
grep "Re-submitted" $LOG | cut -d" " -f13 | sort | uniq -c >> $RES
echo "**************   WHERE IS FAILING?   ***********" >> $RES
grep COMPLETED $LOG | grep -v "exit: 0"| awk '{print $12}'| sed s/\;//g |awk '{out = system("qacct -j "$0)}' | grep hostname | awk '{print $2}'  | sort| uniq -c >> $RES
awk '{if ($0~"Execution complete -- Goodbye") print "####################\nPIPELINE IS FINISHED\n####################"}' $LOG >> $RES



