Use this script to look for a running jenkins job on slave worker
function waitforjob() {
jekins_slave_pid=$(ps -ef|grep slave.jar | awk '{print $2"="$8}'|grep java|awk -F'=' '{print $1}')
if [ ! -z "${jekins_slave_pid}" ] ; then
while pstree -pnlac ${jekins_slave_pid} |grep hudson > /dev/null 2<&1; do
echo 'waiting for job to finish';
sleep 5;
done
else
echo 'slave agent is down'
fi
echo 'jenkins is not running a job'
}
waitforjob