0

Looking for advice. Writing a simple bash script. It will check percentage of income files in folder every 30 min. So we know expected total number of files and till what time they all should be in folder.

So I got stuck with appending value "verification status". If percent of income files is equal or higher then expected, than set status is verified and send email with current data as HTML table. So each script run appending data to file which will to the HTML table.

Table sample:

    |     Time     | Files count| Files rate |  Status  |
    |14:31 21.01.18|    18567   |    15,6%   | Verified |
    |15:01 21.01.18|    21402   |    19,2%   |  Failed  |

Couldn't find solution how to make same script run and check different condition. To me the logic seems to be like that:

if 1st script run and files rate is equal or lower 15% then status=Verified else status=Failed

    if [ $attemptrun -eq 2 ] && [ $filerate -gt 15 ]
    then status=Verified
    else
    status=Failed

But how to make that each additional script run, expecting and checking different file rate, like 1st run =< 15, 2nd =<22, 3rd =<35 etc ?

  • Welcome to Stackexchange UNix , there's absolutely no chance that someone helps you without any information about your script ? What is your problem cleary, describe what is your input, what is your script and what is your intended output and what's your current behavior. – Kiwy Feb 13 '18 at 11:29
  • Either pass the changing value as a parameter, or if the script needs to change it, store it in a file. Or if the value required depends on something else (the current time or some external state perhaps) have the script read that and base its parameters directly on the source. – ilkkachu Feb 13 '18 at 12:57
0

Try this :

 #!/bin/bash

 while IFS='|' read -r _ time count rate status; do
     ((countlines==0)) && continue # skip headers

     time=${time// /} # bash parameter expansion to remove spaces
     count=${count// /} # same thing...
     status=${status// /} # same thing...
     rate=${rate// /}
     echo "time=$time count=$count rate=$rate status=$status"


     if ((${rate%\%} >= 15)) && [[ $status == Verified ]]; then
         status=Verified
     fi

     ((countlines++)) 
 done < file.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.