i need a script that will test if proxy is working or not. Scipt should download a page with wget then grep for specific string of characters. If it can't find the string then it should send a email to specific address. I am having problems with part where it should decide if it found the string or not. export http_proxy='http://proxy.test.cz:1234/'

wget -nvq --proxy-user=test --proxy-password=test google.com &>/dev/null | grep -q '<H1>you cant't use internet</H1>' || ( echo "Proxy isnt't working" | mail -s "Proxy isnt't working!!!" -r "No-reply<no-reply@test.cz>" test@test.cz )
  • Don't reinvent the wheel. There are many programs that can monitor various aspects of a system and send you alerts when services go down. One such program that comes to mind is monit, but there are many others. Feb 13 '17 at 9:21
  • Boss said to do it this way so i dont have choice. Also proble is that the proxy is working all the time just sometimes it allows to visit intnertet for all users. Feb 13 '17 at 9:38
  • Your boss is a manager. You're a technicial (presumably). Suggest a better technical solution that still solves the problem.
    – roaima
    Feb 13 '17 at 9:48
  • That is true, but i also dont want to study another think right now. I have a lot of work and i dont have time for reading manuals. Feb 13 '17 at 9:58
wget -q --spider ${URL}
if [ $? = 0 ]
echo $STATUS

Send mail based on the status value.

  • Thanks for help. I also need it to work without creating a index.html file and to grep that specific string : <H1>You cant use intrenet</H1>. Feb 13 '17 at 10:15
  • Didn't really understand you.You don't want to create a html file and grep the heading? from where?
    Feb 13 '17 at 10:21
  • I am sorry if it is confusing. If you look at this code : wget -nvq --proxy-user=test --proxy-password=test google.com &>/dev/null | grep -q '<H1>you cant't use internet</H1>' it does exectly what i need. I just need to somehow repair my whole code that it will decide correctly. Now it just sends mails even if it finds the string. Feb 13 '17 at 10:51
  • My bad sorry, now i see that wget --spider just looks if the page exists and dont download it. Feb 13 '17 at 11:05

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.