archedraft Posted October 29, 2017 Share Posted October 29, 2017 (edited) I used to have a script that would check if the array was started and parity check was not running before backing up files. Using: #!/bin/bash var=/proc/mdcmd array=$(grep -Po '^mdState=\K\S+' $var) rsync=$(grep -Po '^mdResync=\K\S+' $var) if [[ $array == STARTED && $rsync -eq 0 ]]; then rysnc script fi I saw that from rc8 onwards the preferred method to read array status is by quering the var.ini and disks.ini files. so I updated the a test script to the following: #!/bin/bash var=/var/local/emhttp/var.ini array=$(grep -Po '^mdState=\K\S+' $var) rsync=$(grep -Po '^mdResync=\K\S+' $var) echo $array echo $rsync if [[ $array == STARTED ]]; then echo "ARRAY STARTED" else echo "ARRARY NOT STARTED" fi if [[ $rsync -eq 0 ]]; then echo "RSYNC 0" else echo "RSYNC Running" fi and my output is: "STARTED" "0" ARRARY NOT STARTED ./test: line 17: [[: "0": syntax error: operand expected (error token is ""0"") RSYNC Running Does anyone know why the if else logic is coming back false instead of true like the echo variables are stating? Edited October 29, 2017 by archedraft Quote Link to comment
bonienl Posted October 29, 2017 Share Posted October 29, 2017 Your result includes quotes. Do this: array=$(grep -Po '^mdState="\K[^"]+' $var) 1 Quote Link to comment
archedraft Posted October 29, 2017 Author Share Posted October 29, 2017 1 hour ago, bonienl said: Your result includes quotes. Do this: array=$(grep -Po '^mdState="\K[^"]+' $var) Thank you! @bonienl Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.