Comparing Integers (I think)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing Integers (I think)
# 1  
Old 11-05-2018
Comparing Integers (I think)

Hi,


I can't figure out what I'm missing. I'm running a query to see if there are any streams recording on my DVR before starting a scripted update. I'm guessing that it is viewing $VIDEO as a string instead of an int. I've tried everything I saw on google but it still comes back as $VIDEO is greater than 0, then sends me an email saying that it was delayed because there are 0 stream(s) recording.


I removed one of the t's in http due to link restriction.




Code:
#!/bin/bash
#Check to make sure we aren't recording
DATA=$(curl -sq htps://172-16-99-170.88e7a0e0e4e44af5b00a87c5b0baea80.plex.direct:32400/media/subscriptions/scheduled?X-Plex-Token=XXXXXXXXXXXXXXX)
declare -i VIDEO=$(echo "$DATA" | grep '<MediaGrabOperation' | grep 'status="inprogress"'|wc -l)
if (( $Video > 0 ))
then
Path=$1
Version=${Path##*/}
echo $Path >> /home/rhysers/log.txt
ssh plex@172.16.99.170 -p 778 -o StrictHostKeyChecking=no "rm /tmp/plex*"
ssh plex@172.16.99.170 -p 778 "wget -P /tmp/ $Path" >> /home/rhysers/log.txt
ssh plex@172.16.99.170 -t -p 778 "sudo dpkg -i /tmp/$Version" >> /home/rhysers/log.txt
curl "htp://127.1.2.3:8181/tautulli/api/v2?apikey=XXXXXXXXXXXXXXXXXXXXX&cmd=notify&notifier_id=5&subject=Plex+Update+Completed&body=Completed+Update+Cycle+to+$Version+on+$(date +%Y-%m-%d@%H:%M:%S)"
else
curl "htp://127.1.2.3:8181/tautulli/api/v2?apikey=XXXXXXXXXXXXXXXXXXXXX&cmd=notify&notifier_id=5&subject=Plex+Update+DELAYED&body=Update+Delayed+because+there+is+$VIDEO+item(s)+recording"
fi

# 2  
Old 11-05-2018
VIDEO != Video
This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 11-05-2018
ZOMG how did I miss that.
#hangsHeadInShame

------ Post updated at 09:23 AM ------

OK, so while that certainly wasn't helping, it also didn't fix it. I still get Delayed because there is 0 stream(s) recording.


Code:
#!/bin/bash

#Check to make sure we aren't recording
DATA=$(curl -sq https://172-16-99-170.88e7a0e0e4e44af5b00a87c5b0baea80.plex.direct:32400/media/subscriptions/scheduled?X-Plex-Token=XXXXXXXXXXXXXX)
declare -i VIDEO=$(echo "$DATA" | grep '<MediaGrabOperation' | grep 'status="inprogress"'|wc -l)

if (( $VIDEO > 0 ))
then
Path=$1
Version=${Path##*/}
echo $Path >> /home/rhysers/log.txt
ssh plex@172.16.99.170 -p 778 -o StrictHostKeyChecking=no "rm /tmp/plex*"
ssh plex@172.16.99.170 -p 778 "wget -P /tmp/ $Path" >> /home/rhysers/log.txt
ssh plex@172.16.99.170 -t -p 778 "sudo dpkg -i /tmp/$Version" >> /home/rhysers/log.txt
curl "http://127.1.2.3:8181/tautulli/api/v2?apikey=XXXXXXXXXXXXXXXXXX&cmd=notify&notifier_id=5&subject=Plex+Update+Completed&body=Completed+Update+Cycle+to+$Version+on+$(date +%Y-%m-%d@%H:%M:%S)"
else
curl "http://127.1.2.3:8181/tautulli/api/v2?apikey=XXXXXXXXXXXXXXXXXX&cmd=notify&notifier_id=5&subject=Plex+Update+DELAYED&body=Update+Delayed+because+there+is+$VIDEO+item(s)+recording"
fi

# 4  
Old 11-05-2018
Add set -x as the second line in your script and rerun.
what's the output of your curl?
Please use code tags when posting.
# 5  
Old 11-05-2018
Ok, the first curl to see if there is a recording going on is over 800 lines, you can view it here: Curl Response - Pastebin.com


The part I think you might be looking for at the end is this:


Code:
+ declare -i VIDEO=0
+ ((  0 > 0  ))
+ curl 'http://127.1.2.3:8181/tautulli/api/v2?apikey=e74b2a5a44054bab9c760ace16ac7310&cmd=notify&notifier_id=5&subject=Plex+Update+DELAYED&body=Update+Delayed+because+there+is+0+item(s)+recording'
{"response": {"message": "Notification sent.", "data": {}, "result": "success"}}rhysers@mypi:/etc/updatePlex $


Also, am I not using code tags correctly? I thought I was and I can see it treat my code differently than standard text.


Thanks!

------ Post updated at 10:20 AM ------

Holy shampoo my logic statement is backwards. Hold on while i fix it and try it again.
I guess it "worked" when $VIDEO was >0 because I was actually evaluating $Video, which was 0.
Thanks for working through this with me.

------ Post updated at 10:23 AM ------

That fixed it! Thanks for the help!
# 6  
Old 11-05-2018
your nested grep (grep '<MediaGrabOperation' | grep 'status="inprogress"') returns no matches given your sample curl output.
I'd suggest start off by capturing the output of curl in a file and debug the script statically first.
# 7  
Old 11-05-2018
At this moment that's exactly what it should do. There are no recordings in progress so it should return 0. If there were recordings in progress there would be that many matches. If there are 0 matches then it should proceed with the update. If there are matches then it doesn't because the update would interrupt the recording.
I fixed the logic to If $VIDEO < 1
Everything works now.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Strings to integers?

Hi, I'm totally new at this, so help will be appreciated. I have a directory with a bunch of files in it. The files are named xinteger_yinteger_zinteger.vtk (eg, x3_y0_z-1.vtk). I want to read the filenames and then assign the integers to variables that I then can use in expressions. So, for... (6 Replies)
Discussion started by: jhsinger
6 Replies

2. Shell Programming and Scripting

Bash Integers/String

Hy friends, I am newbie to bash scripting, can anyone explain how b=${a/23/BB} # Substitute "BB" for "23". this line converts "b" into string and and "d" into Integer. Thanks in advance (4 Replies)
Discussion started by: Qazi
4 Replies

3. Shell Programming and Scripting

Grep float/integers but skip some integers

Hi, I am working in bash in Mac OSX, I have following 'input.txt' file: <INFO> HypoTestTool: >>> Done running HypoTestInverter on the workspace combined <INFO> HypoTestTool: The computed upper limit is: 11 +/- 1.02651 <INFO> HypoTestTool: expected limit (median) 11 <INFO> HypoTestTool: ... (13 Replies)
Discussion started by: Asif Siddique
13 Replies

4. Shell Programming and Scripting

Cancel down 2 integers

Wonderful evening to all of you! My problem has to possible starting points. Well, not really, but getting to either one is no problem at all. So i got either a string in the format of "1920x1080" or simply the integers X = 1920 and Y = 1080. When I am done, I would like to have an output... (5 Replies)
Discussion started by: jakunar
5 Replies

5. Shell Programming and Scripting

Strings to integers in an arithmetic loop

Hi all, Could someone please advise what is the correct syntax for my little script to process a table of values? The table is as follows: 0.002432 20.827656 0.006432 23.120364 0.010432 25.914184 0.014432 20.442655 0.018432 20.015243 0.022432 21.579517 0.026432 18.886874... (9 Replies)
Discussion started by: euval
9 Replies

6. Shell Programming and Scripting

integers, floats and text

I am using gawk in a dos shell in windows xp and want to read a datafile and reformat it. The datafile consists of columns of integers, floating point numbers and text strings. Each column is a fixed width and each column contains the same data type, eg all integers, all text. I am looking for a... (0 Replies)
Discussion started by: lookingfor help
0 Replies

7. Shell Programming and Scripting

Add non-integers using ksh

I would like to add 4.7 and 1.2. However I am unable to do this with expr. Any simple ideas (even using something other than expr)? Example: me> expr 4 + 1 5 me> expr 4.7 + 1.2 expr: 0402-046 A specified operator requires numeric parameters. (18 Replies)
Discussion started by: 2dumb
18 Replies

8. Shell Programming and Scripting

bash problem when comparing integers

Hi, When I compare currentfiledate to reportfiledate I get a "-bash: currentfiledate=20090220080101 reportfiledate=20090219231245 if ; then echo -ne "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! \n" echo -ne "!! Running the load utility !! \n" fi Our... (15 Replies)
Discussion started by: rbournival
15 Replies

9. Programming

Using write() with integers in C

I'm trying to write an integer to a file using the write() function, but write() requires the parameter to be written to be a const void*. How would I go about doing this? also: using itoa() produces a " warning: implicit declaration of function 'itoa' " even though i have #included stdlib.h (2 Replies)
Discussion started by: h@run
2 Replies

10. Shell Programming and Scripting

integers in the if statement

hi, im trying to compare two variables in csh to put in an if statement, eg: set a = $firstnum set b = $secondnum if ($a -ge $b) echo $a But I get an error ("if: Expression syntax"). How can I make csh see my variables as integers? thanks in advance! (5 Replies)
Discussion started by: Deanne
5 Replies
Login or Register to Ask a Question