0

My goal is to monitor a web page for text and trigger an email to myself either if the text is found, or if it is not, whichever is easier. I know there are some packages out there already to do this, but I'm trying to learn a bit more command line in the process of figuring this out.

The use case is to search for text like "sale starting in" or something like that, so I get an alert when that text is no longer there.

I've done some digging and have the two commands I need, but want to be able to tie them together into a job that I can schedule in cron. A single shell command line would be preferred. I do have perl installed if a script is needed.

An example of a successful search is

curl -s -k http://www.scifi-review.net | grep stettin

result: the source code line with the pattern mach

An example of no result is

curl -s -k http://www.scifi-review.net | grep xxxxxxx

result: just goes back to command line

My email command (I installed an configured ssmtp)

echo "Subject: Test"| ssmtp myemail@domain.com

I'm looking at doing something like this:

If Curl command has NO output, run the email command. (preferred)

or

If Curl command HAS output, run the email command.

1

Assuming you are using bash as your shell,

if [[ $(curl -s -k http://www.scifi-review.net | grep stettin) ]]; then echo "Subject: Test"| ssmtp myemail@domain.com; fi

  • I figured out the false version if [[ $(curl -s -k http://www.scifi-review.net | grep xxxxxxxxx) ]]; then echo "there was a match"; else echo "Subject: Test-false"| ssmtp myemail@domain.com; fi – Stettin Mar 9 '18 at 20:59

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.