BASH script to control suspend from crontab

Hi,

I wanted to have some more control over suspend of my server than available OOTB. For example, I do not want to suspend my server if there active remote ssh/sftp sessions or if there are 'slurm' jobs running. The following bash script that I run every 5 minutes out of root's crontab achieves that:

#!/bin/bash
#the file $AWAKE will be created if the system should not suspend
AWAKE=$HOME/.AWAKE
rm -f $AWAKE
#check for active login sessions
loginctl --no-legend list-sessions | while read SESSION IGNORE
do
  IDLESINCEHINT=$( loginctl --no-legend -p IdleSinceHint show-session $SESSION )
  IDLESINCEHINT=${IDLESINCEHINT#*=}
  #echo session=$SESSION IdleSinceHint=$IDLESINCEHINT
  if (( $IDLESINCEHINT > 0 ))
  then
    IDLEHINT=$( loginctl --no-legend -p IdleHint show-session $SESSION )
    IDLEHINT=${IDLEHINT#*=}
    #echo session=$SESSION IdleHint=$IDLEHINT
    if [ $IDLEHINT == "no" ]
    then  
      touch $AWAKE
    fi
  fi
done
#Other things you would like to check
#As an example, I do not want to suspend my server if there are
#slurm jobs running in the 'long' partition
if squeue -h | grep long >/dev/null
then
  touch $AWAKE
fi
#
#I can manually override suspend by creating the file /home/gwies/.AWAKE
#
if [ -f /home/gwies/.AWAKE ]
then
  touch $AWAKE
fi
if [ ! -f $AWAKE ]
then
  logger SUSPENDING..
  systemctl suspend
fi

Regards,
GW