0

I'm a bit messed up with while read and If routines.

I'm trying to create a bash script for Linux which reads the processed clean numerical output from rsstail and if the numerical output is greater than 5.5 then it executes another script I already have.

The main command for rsstail I'm running is checking for the newest RSS every 3 seconds and gets the first clean 3-5 characters which are the numbers I need, using the following:

rsstail -i 3 -u http://someserver/somefile.xml -n 1 -N | cut -c 3-5

The output of that is a single number like

3.7

Then I need to compare constantly the numerical output and IF it is greater than 5.5, then execute another script I already have. If it is not, do nothing but continue to check the rsstail output for values greater than 5.5

lefleflef
  • 3
  • 1

2 Answers2

0

You might use GNU AWK for this task following way, pipe your output i.e. single line with value like

3.7

into

awk '{if($1>5.5){system("bash yourscript.sh")}}'

This will do bash yourscript.sh if condition is meet else it will do nothing. Keep in mind that system Execute the operating system command command and then return to the awk program. Return command’s exit status

Daweo
  • 31,313
  • 3
  • 12
  • 25
0

Since you are performing a numerical test with floating numbers, you could invoke bc to do the job.

Try

#!/bin/bash

while true; do
  output=$(rsstail -i 3 -u http://someserver/somefile.xml -n 1 -N | cut -c 3-5)
  condition=$(echo "($output - 5.5) > 0" | bc)
  if [ "$condition" -eq 1 ]
    then echo "executing other script"
  fi
  sleep 3
done
Pierre François
  • 5,850
  • 1
  • 17
  • 38