I am trying to pull information from a simple bash script that pulls some data from a java server. When the SSH variable is run in the script, I can't seem to run awk on it to pull out the information I need unless I write it to a local file. Here's what I am working with:
check=$(ssh [email protected] "/usr/local/bin/check_mq.sh")
ret=$?
cat=/bin/cat
awk=/usr/bin/awk
output=$($cat $check | $awk -F= '{print $4}' | $awk '{print $1}')
echo $output
If I just echo $check in the script it comes up like this.
backchannel_queue messages=0 messages_ready=0 messages_unacknowledged=0
But, if I put $check in the script with the awk commands it gives me this output:
/bin/cat: backchannel_queue: No such file or directory
/bin/cat: 'messages=0': No such file or directory
/bin/cat: 'messages_ready=0': No such file or directory
/bin/cat: 'messages_unacknowledged=0': No such file or directory
I have been able to get this working by writing $output to a text file on the system with:
check_output="/home/user/Documents/scratch/check_output.txt"
echo $check > $check_output
output=$($cat $check_output | $awk -F= '{print $4}' | $awk '{print $1}')
echo $output
I am thinking there has to be something I am doing wrong here and I shouldn't need to write $output to a file. Or, is that the only option here? Once I have that number in a variable I plan to use some IF statements to see if it's greater than x, etc.