0

The autostatus will give a status of RUNNING or SUCCESS or FAIL to the jobstat variable. This hack script works fine. Until I wanted to add some pazazzz. If jobstat equals SUCCESS, It would be cool to print it out on to the terminal in green. Anything else, like RUNNING or FAIL print out red.

#!/bin/bash
jobname=$1
hostnam=$(hostname -f | cut -d"." -f2 )
red=$(tput setaf 1)
green=$(tput setaf 2)
reset=$(tput sgr0)
hemisphere="PADC"

while true
do
jobstat=$(autostatus -J $jobname)
choptim=$(date | awk '{print $4}')
    if [[ "$jobstat" == "SUCCESS" ]]; then
     echo "$hemisphere $choptim ${green} ${jobstat} ${reset} $jobname"
     else
     echo "$hemisphere $choptim ${red}${jobstat}${reset} $jobname"
fi
done

However when i run it i get this error

line 14: conditional binary operator expected
line 14: syntax error near `$choptim'
line 14: `echo "$hemisphere $choptim ${green} ${jobstat} ${reset} $jobname"'
capser
  • 2,442
  • 5
  • 42
  • 74
  • 1
    Possible duplicate of [How to change the output color of echo in Linux](https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux) – Ollin Boer Bohan Jul 11 '18 at 22:35
  • 3
    Your error talk about line 24 but your script is only 17 lines. Can you please copy-paste the code from your post into a new file and rerun it to make sure that it does in fact reproduce the issue you're asking about, and then update the error? – that other guy Jul 11 '18 at 22:36
  • Use an hex editor to check for invisible annoying characters, like DOS line-endings (CRLF), Unicode non-breaking space, etc. – xhienne Jul 11 '18 at 22:42
  • "How to change the output color of echo in Linux" assigns colors to strings. I am trying to assign colors to variables. – capser Jul 11 '18 at 22:44
  • @capser - they are variables in both cases. – Stephen C Jul 11 '18 at 22:47
  • echo "$(tput setaf 1)Hello, world$(tput sgr0)" - hello world is a string. I am trying to color $jobstat, which is a variable --- echo "$(tput setaf 1) $jobstat $(tput sgr0)" - i dont see and example like that on the duplicate page. – capser Jul 11 '18 at 22:53
  • never mind - I found the issue - forgot one set of apostrophes in test conditions – capser Jul 11 '18 at 23:10

0 Answers0