|
|
Help with simple shell script
|
|
|
|
Mac Enthusiast
Join Date: Jan 1999
Location: Marietta, GA, USA
Status:
Offline
|
|
Code:
#!/bin/bash
if [curl http://www.appleturns.com/ > grep -q "mass backsies"]
then
echo "Jack is still away"
else
echo "He's back!"
fi
I'm close I think. How do I search this page for the specified text, then do something if it's there?
Thanks,
-Scott
|
Scott Genevish
scott AT genevish DOT org
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status:
Offline
|
|
I'd dump it to file, grep the file, then remove the file.
This uses grep to count the matches found and drops that number into a var as an int.
then just test the int.
Code:
#!/bin/bash
curl http://www.appleturns.com/ > temp.html
c=`grep -c "mass backsies" temp.html`
if [ "$c" -ge "1" ]
then
echo "He's back!"
else
echo "Jack is still away"
fi
rm temp.html
|
You can take the dude out of So Cal, but you can't take the dude outta the dude, dude!
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Sep 2005
Location: Rochester, NY
Status:
Offline
|
|
Originally Posted by genevish
I think you want a pipe there , not a redirect. That will send the output of the "curl" command directly to "grep" via STDIO without creating an intermediate file. Or something like that.
Try
[/QUOTE]
(
Last edited by Dork.; Oct 5, 2005 at 08:40 AM.
)
|
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jan 1999
Location: Marietta, GA, USA
Status:
Offline
|
|
OK, here's my final solution. I installed the command line tool growlnotify that can pass a message to Growl. This script runs every hour:
Code:
#!/bin/bash
curl -s http://www.appleturns.com/ > temp.html
c=`grep -c "mass backsies" temp.html`
if [ $c == 0 ]
then
/usr/local/bin/growlnotify -s "Jack Alert" -m 'Jack is Back!'
fi
rm temp.html
Thanks for the help!
|
Scott Genevish
scott AT genevish DOT org
|
|
|
|
|
|
|
|
Mac Enthusiast
Join Date: Jan 1999
Location: Marietta, GA, USA
Status:
Offline
|
|
OK, I was so pleased with how this worked, I'd like to modify it to detect whenever this website is updated. I see the pseudo-code as follows:
- Check if website has changed using Grep
- If changed, display alert and then re-write the text searched for in Grep.
I think I can muddle through re-writing the Grep expression, but I'm not sure how to dynamicaly re-write the script to display the new search string. Should I use something like cat $theScript > file.sh? Is there a better way?
Thanks,
-Scott
|
Scott Genevish
scott AT genevish DOT org
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|