kapperz Posted May 1, 2010 Share Posted May 1, 2010 I've written a script that will run an encoding job with Handbrake whenever a file is found in a certain directory. Everything works great. I also check to make sure HandbrakeCLI is not already running before queuing any new file in the directory. I would also like to prevent the encode queue if the parity check is currently running. How can I check this in a script? Many thanks I'm using unRaid 4.5 Link to comment
Joe L. Posted May 1, 2010 Share Posted May 1, 2010 I've written a script that will run an encoding job with Handbrake whenever a file is found in a certain directory. Everything works great. I also check to make sure HandbrakeCLI is not already running before queuing any new file in the directory. I would also like to prevent the encode queue if the parity check is currently running. How can I check this in a script? Many thanks I'm using unRaid 4.5 you need to use the following as a guide. If parity sync is not running you get this root@Tower:/boot# /root/mdcmd status | grep Resync mdResync=0 If it is running, you get something like this: root@Tower:/boot# /root/mdcmd status | grep Resync mdResync=976762552 mdResyncPos=90240 mdResyncPrcnt=0.0 mdResyncFinish=3605.2 mdResyncSpeed=4512 You can basically just grep for "mdResync=" If it is anything other than 0, a parity check is running. Link to comment
kapperz Posted May 1, 2010 Author Share Posted May 1, 2010 Thanks for the quick reply. Executing /root/mdcmd status | grep Resync gives me one of the two result (while parity is running) in telnet... Binary file (standard input) matches OR mdResync=1465138552 mdResyncPos=1029122472 mdResyncPrcnt=70.2 mdResyncFinish=86.7 mdResyncSpeed=83788 I'm a novice at scripting, but not a total n00b. Could you help a little more with the code? #!/bin/bash if [ $(/root/mdcmd status | grep Resync) -ne 0 ] then echo "Parity running" else echo "Not Running" fi Link to comment
kapperz Posted June 9, 2010 Author Share Posted June 9, 2010 Just a note. If parity is not running, you need to add the -a option to grep if [ $(/root/mdcmd status | grep -a Resync= | cut -c10) == '0' ] then echo "### Parity NOT running ###" fi Link to comment
warhead Posted June 10, 2010 Share Posted June 10, 2010 if [ `/root/mdcmd status | grep -aw mdResync | awk -F= '{print$2}'` != 0 ]; then echo "Parity check in progress" return 1 fi Your version of just doing grep-a Resync could have problems in the event where parity check is running as grep would return multiple lines and the test statement won't handle it. the -w flag forces grep to match the word entirely. awk -F= '{print$2}' is a neater way of selecting the data after the equal sign IMO Link to comment
Joe L. Posted June 10, 2010 Share Posted June 10, 2010 if [ `/root/mdcmd status | grep -aw mdResync | awk -F= '{print$2}'` != 0 ]; then echo "Parity check in progress" return 1 fi Your version of just doing grep-a Resync could have problems in the event where parity check is running as grep would return multiple lines and the test statement won't handle it. the -w flag forces grep to match the word entirely. awk -F= '{print$2}' is a neater way of selecting the data after the equal sign IMO And yours might choke if something other than a numeric value is returned at some point in the future, or nothing is returned. Probably better to put the "0" in "quotes" as well as the entire `grep ...| awk ` command" if [ "`/root/mdcmd status | grep -aw mdResync | awk -F= '{print $ 2}'`" != "0" ]; then echo "Parity check in progress" return 1 fi Link to comment
warhead Posted June 10, 2010 Share Posted June 10, 2010 And yours might choke if something other than a numeric value is returned at some point in the future, or nothing is returned. Future proofing - good catch Link to comment
kapperz Posted June 11, 2010 Author Share Posted June 11, 2010 Thanks all. I'm still learning. Link to comment
Recommended Posts
Archived
This topic is now archived and is closed to further replies.