Score:0

Getting a syntax error when running the test.sh file "./test.sh: 36: Syntax error: end of file unexpected (expecting "done")"

cn flag

I'm getting this syntax error when running the test.sh file:

./test.sh: 36: Syntax error: end of file unexpected (expecting "done")

test.sh:

#!/bin/sh

# WebHook
url="DiscordWebHook"
hostname="TestingSvr01"
PublicIP="My IP"

# check current disk usage
df -H | grep -vE '^Filesystem|tmpfs|cdrom|loop' | awk '{ print $5 " " $6 }' | while read output;

# assign variables
do
  #echo $output
  used=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
  USERNAME=\"${hostname}\"
  PUBLICIP=\"${PublicIP}\"
  msg_content=\"$message\"
  DISCORD_WEBHOOK_URL="${url}"

  # if disk reached the threshold, send a notification to Discord #Infra. 
  if [ $used -ge 85 ]; then
curl -H "Content-Type: application/json" -X POST -d "{\"used\": $used, \"partition\": $partition, \"username\": $USERNAME, \"IP\": $publicIP, \"content\": $msg_content}" $DISCORD_WEBHOOK_URL
  else
    echo "${output}  failed"
  fi
exit 0
Done
Score:3
sa flag

Done in the last line is case sensitive. bash is expecting done, so use done (all lowercase) instead.

Here are the results of checking your bash shell script at https://www.shellcheck.net/.

enter image description here

PublicIP in PUBLICIP=\"${PublicIP}\" does not match publicIP in curl -H "Content-Type: application/json" -X POST -d "{"used": $used, "partition": $partition, "username": $USERNAME, "IP": $publicIP, "content": $msg_content}" $DISCORD_WEBHOOK_URL Use PUBLICIP=\"${publicIP}\" instead.

You can install ShellCheck in Ubuntu with sudo apt install shellcheck and run it with shellcheck test.sh ShellCheck would be a very convenient tool to use for checking your shell script because it points to the exact location of the error in each line where an error that it found is located.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.