Skip to content

Instantly share code, notes, and snippets.

@wuftymerguftyguff
Last active February 16, 2017 10:53
Show Gist options
  • Save wuftymerguftyguff/34d80718270fc0132e1baa2c83d260fe to your computer and use it in GitHub Desktop.
Save wuftymerguftyguff/34d80718270fc0132e1baa2c83d260fe to your computer and use it in GitHub Desktop.
Script to adjust the number of R3load processes runnng in a SAP export or import when split tables have complete
#!/usr/bin/bash
#BE CAREFUL!!! THIS CAN RUN AMOK
TARGETJOBS=32
CFGFILE="import_monitor_cmd.properties"
CNT=$(ps -ef | grep R3load | grep -v grep | wc -l)
CONFIGURED=$(grep jobNum $CFGFILE | awk -F= '{print $2}')
WAITING=$(grep 'Monitor jobs' import_monitor.log | tail -1 | grep -e running -e waiting | awk '{print $6}' | sed s/,//g)
LOADAVG15=$(uptime | awk {'print $12'} | awk -F. '{print $1}')
NUMCPUS=$(grep -c ^processor /proc/cpuinfo)
SPARECPU=$(( $NUMCPUS / $LOADAVG15 ))
echo Target Job Count: $TARGETJOBS
echo Current Running Jobs: $CNT
echo Current Configured Jobs: $CONFIGURED
echo Current Waiting Jobs: $WAITING
echo 15 Minute Load Averge: $LOADAVG15
echo CPUs visible to OS: $NUMCPUS
echo Spare Capacity: $SPARECPU
if [ $CNT -lt $TARGETJOBS ] && [ $CONFIGURED -lt $TARGETJOBS ] && [ $WAITING -gt "1" ]
then
echo ramping up, as less than target jobs running
NEW=$((CONFIGURED+1))
perl -p -i -e 's/jobNum='$CONFIGURED'/jobNum='$NEW'/' $CFGFILE
fi
if [ $SPARECPU -ge 1 ] && [ $WAITING -gt "1" ]
then
NEW=$((CONFIGURED+SPARECPU))
echo ramping up as we have spare cpu adding $SPARECPU R3loads
perl -p -i -e 's/jobNum='$CONFIGURED'/jobNum='$NEW'/' $CFGFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment