vendredi 12 février 2021

(Root-Crontab) Curl is executed anyway in if-statement

I have a root crontab (sudo crontab -e), in a bash script I check if the user is my main account (so not root or any other user).

The variable $CHECK_XHOST is empty here normally but this code block should not be executed at all because it is inside the whoami if-block.

However, this works only partially, all commands are not executed except for the curls, the curls are executed anyway, what is the reason?:

# skipping xhost check if user is not 'USERNAME'
if [ `/usr/bin/whoami` == 'USERNAME' ]; then

  CHECK_XHOST=$(/usr/bin/xhost | grep 'SI:localuser:root' | tr -d '\r')
  CHECK_XHOST_ALL=$(/usr/bin/xhost | tr -d '\r' | sed -z 's/\n/ | /g' | rev | cut -c4- | rev)

  if [ -z "$CHECK_XHOST" ]; then
      echo "XHOST => INCORRECT (${CHECK_XHOST_ALL}) !!PROBLEM!!" 
      curl --silent -X POST -F "API=${API_KEY}" -F "name=xhostCheck" -F "value=XHOST => INCORRECT (${CHECK_XHOST_ALL}) !!PROBLEM!!" https://domain.tld/test.php > /dev/null
      ERRORS=$((ERRORS+1))
  else
      echo "XHOST => CORRECT (${CHECK_XHOST_ALL})" 
      curl --silent -X POST -F "API=${API_KEY}" -F "name=xhostCheck" -F "value=XHOST => CORRECT (${CHECK_XHOST_ALL})" https://domain.tldtest.php > /dev/null
  fi

fi

Aucun commentaire:

Enregistrer un commentaire