Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: Server paging option

  1. #1
    Join Date
    Feb 2006
    Location
    NM
    Posts
    29

    Default Server paging option

    Hello,

    I got a odd but weird question. I have weather software on my computer that uploads files every 5 minutes using FTP for my weather page.

    My question is, is there software or anything I can put on the server that if the page (or file --lets say "index.html") doesn't update within 1 hour or so that I could have it page me via cell phone letting me know that there might be a problemn and the page isn't updating. This would really help me in case my computer locks up and im not home or gone one weekend.

    I'm sure some other users have experienced this and im not sure if this would be a php thing or whatnot...but its been bugging me and needed to be pointed in the right direction.

    Thanks! :-)
    Jason
    Portales, NM Weather
    www.portalesweather.net

  2. #2
    Join Date
    Feb 2006
    Posts
    28

    Default

    Well, probably the most basic solution to this would be a shell script that runs as part of a Cron job.

    You can setup Cron jobs in the cPanel, and you would basically just set something up that would run every hour and check the timestamp on the page that you're looking for, using a relatively simple "if" construct in the script, and then use the mail command to send an e-mail out to your cell phone's e-mail address if necessary.

    The easy way to do this would probably be with shell access, but if you don't have that, you could probably still compose the script offline and upload it manually.

    I am by no means a shell scripting expert, so there's probably a more elegant way to do this, but a script like the following would probably work:

    Code:
    #!/bin/bash
    
    if [ "path-to-real-file" -nt "path-to-reference-file" ] then
          touch "path-to-reference-file"
    else
          mail your-address@yourdomain.com -s a subject line <message-body-file
    fi
    Essentially, what this should do is create a reference file with the current date and time the first time it's run, and then use that as a timestamp reference to determine the last time the real file was checked as a comparison. The next time the script runs, it checks to see if the real file is newer than the reference file (ie, it's been updated since the last check), and if this is the case, it updates the timestamp on the reference file ("touch" command). If not, the else condition is run, which sends out an e-mail message using the text in a specific file as the body (or just use /dev/null if you don't want a message body but just a subject line).

    Provided you have an e-mail address associated with your SMS service for your cell phone, you could simply provide that e-mail address in the script.

  3. #3
    Join Date
    Feb 2006
    Location
    NM
    Posts
    29

    Default

    Quote Originally Posted by jdh
    Well, probably the most basic solution to this would be a shell script that runs as part of a Cron job.

    You can setup Cron jobs in the cPanel, and you would basically just set something up that would run every hour and check the timestamp on the page that you're looking for, using a relatively simple "if" construct in the script, and then use the mail command to send an e-mail out to your cell phone's e-mail address if necessary.

    The easy way to do this would probably be with shell access, but if you don't have that, you could probably still compose the script offline and upload it manually.

    I am by no means a shell scripting expert, so there's probably a more elegant way to do this, but a script like the following would probably work:

    Code:
    #!/bin/bash
    
    if [ "path-to-real-file" -nt "path-to-reference-file" ] then
          touch "path-to-reference-file"
    else
          mail your-address@yourdomain.com -s a subject line <message-body-file
    fi
    Essentially, what this should do is create a reference file with the current date and time the first time it's run, and then use that as a timestamp reference to determine the last time the real file was checked as a comparison. The next time the script runs, it checks to see if the real file is newer than the reference file (ie, it's been updated since the last check), and if this is the case, it updates the timestamp on the reference file ("touch" command). If not, the else condition is run, which sends out an e-mail message using the text in a specific file as the body (or just use /dev/null if you don't want a message body but just a subject line).

    Provided you have an e-mail address associated with your SMS service for your cell phone, you could simply provide that e-mail address in the script.
    JDH,

    Thank You so much for your reply. I logged into my bluehost account and checked out the cronjobs and it only gives me one command line not 5 so the if statement wouldn't work there. Unless there is a shorter way I can use that line or im doing something wrong. LOL I copied and pasted that code you have above to notepad but several issues I ran into. WHat directory do I store the saved file to and also what would be the best extention to call it? (.txt., .html, etc) Does it need to be a certain extention?

    If this helps I would love to have the index.html be the file it checks since thats the main website file. I really wouldn't want a body in the email just a subject line to say "index.html hasn't been updated in 60 minutes" or something along those lines.

    I'd personally like to use Cronjob since its like right there and it could do the rest. Although if i have to do the file myself and ftp it onto the server thats fine, I just need to know what directory its in, when I looked before posting this message, i couldn't find where to put it :-(

    Thanks!
    Jason
    Portales, NM Weather
    www.portalesweather.net

  4. #4
    Join Date
    Feb 2006
    Posts
    28

    Default

    Well, you should be able to call the file anything you want, since extensions don't really mean anything in Unix. Some people use a ".sh" extension to define the file as a shell script, but that's not really necessary.

    What you would do is paste the code above (modified appropriately for your situation) into a file, and then FTP that file up to your account. You can drop it in your main home directory if you like, or anywhere else.

    You would then need to perform one more step to make it executable. If you have shell access (SSH), you could just log in and run "chmod 700 <filename>", which would grant read, write, and execute permission to the file. If you don't have shell access, you can do this through the cPanel file manager by selecting the file and choosing "Change Permissions" from the menu. Make sure you select the checkbox beside "Execute" in the "User" column, which will give your script execution permission for your userid.

    In the cron job, you then specify the path to the script as "/home/<yourusername>/<yourscriptfilename>" (assuming you've placed the script in your main home directory).

  5. #5
    Join Date
    Feb 2006
    Location
    NM
    Posts
    29

    Default

    Quote Originally Posted by jdh
    Well, you should be able to call the file anything you want, since extensions don't really mean anything in Unix. Some people use a ".sh" extension to define the file as a shell script, but that's not really necessary.

    What you would do is paste the code above (modified appropriately for your situation) into a file, and then FTP that file up to your account. You can drop it in your main home directory if you like, or anywhere else.

    You would then need to perform one more step to make it executable. If you have shell access (SSH), you could just log in and run "chmod 700 <filename>", which would grant read, write, and execute permission to the file. If you don't have shell access, you can do this through the cPanel file manager by selecting the file and choosing "Change Permissions" from the menu. Make sure you select the checkbox beside "Execute" in the "User" column, which will give your script execution permission for your userid.

    In the cron job, you then specify the path to the script as "/home/<yourusername>/<yourscriptfilename>" (assuming you've placed the script in your main home directory).
    AHA, I made it excute on the server but no reference file is being created. Do I have this code right? I'm not familar with unix programming and i'm sure you can catch any errors before I can.

    I called this file page.sh (per your suggestion)

    Code:
    #!/bin/bash
    
    if ["index.html" -nt "reference.txt"] then
          touch "reference.txt"
    else
          mail your-jayman228@verizon.net -s a subject line "Page down" /dev/null
    fi
    I went to con jobs and entered "/home/hobartwe/public_html/page.sh" in the command line. I told it to update every 1 minute just to beta test, if that works im then going to take my site down for 30 minutes after I change the time to 30 minutes and also modify my email address to my cell phone and see what happends!

    Thanks!
    Jason
    Portales, NM Weather
    www.portalesweather.net

  6. #6
    Join Date
    Feb 2006
    Posts
    28

    Default

    Quote Originally Posted by jayman228
    AHA, I made it excute on the server but no reference file is being created. Do I have this code right? I'm not familar with unix programming and i'm sure you can catch any errors before I can.
    You just have a couple of minor syntax errors... Try the following, with changes in bold:
    Code:
    #!/bin/bash
    
    if ["index.html" -nt "reference.txt"] then
          touch reference.txt
    else
          mail your-jayman228@verizon.net -s a subject line "Page down" </dev/null
    fi
    Basically, there should be no quotes around the filename in the "touch" statement, and you need to make sure that the redirect-in symbol ("<") is in front of /dev/null, since you're basically drawing input from that into mail (which would otherwise default to requesting input from the console).

  7. #7
    Join Date
    Feb 2006
    Location
    NM
    Posts
    29

    Default

    Quote Originally Posted by jdh
    Basically, there should be no quotes around the filename in the "touch" statement, and you need to make sure that the redirect-in symbol ("<") is in front of /dev/null, since you're basically drawing input from that into mail (which would otherwise default to requesting input from the console).
    JDH,

    I did all that and when I checked my email I saw this in there.

    /home/hobartwe/public_html/page.sh: line 5: syntax error near unexpected token `else'
    /home/hobartwe/public_html/page.sh: line 5: `else'

    Looks like were getting close though.
    Jason
    Portales, NM Weather
    www.portalesweather.net

  8. #8
    Join Date
    Feb 2006
    Posts
    7

    Default

    Looks like you're just missing a semicolon on the first line:

    Code:
    if [ "index.html" -nt "reference.txt" ]; then
          touch reference.txt
    else
          mail your-jayman228@verizon.net -s a subject line "Page down" </dev/null
    fi

  9. #9
    Join Date
    Feb 2006
    Location
    NM
    Posts
    29

    Default

    Quote Originally Posted by rcflyer
    Looks like you're just missing a semicolon on the first line:

    Code:
    if [ "index.html" -nt "reference.txt" ]; then
          touch reference.txt
    else
          mail your-jayman228@verizon.net -s a subject line "Page down" </dev/null
    fi
    RCFlyer,

    I did exactly what you mentioned and this is the email I got!

    /home/hobartwe/public_html/page.sh: line 5: syntax error near unexpected token `fi'
    /home/hobartwe/public_html/page.sh: line 5: `fi'

    Below is my code for page.sh
    Code:
    #!/bin/bash
    
    if [ "index.html" -nt "reference.txt" ]; then
          touch reference.txt
    else
          mail your-jayman228@verizon.net -s a subject line "Page down" </dev/null
    fi
    Jason
    Portales, NM Weather
    www.portalesweather.net

  10. #10
    Join Date
    Feb 2006
    Posts
    28

    Default

    Odd.... RCFlyer had it, it was the missing semi-colon (or you could drop the "then" to a separate line, it's the same difference):

    Code:
    #!/bin/bash
    
    if [ "index.html" -nt "reference.txt" ]
    then
          touch reference.txt
    else
          mail your-jayman228@verizon.net -s a subject line "Page down" </dev/null
    fi
    Also, make sure there's a blank line after the "fi" statement... It's possible that might be confusing it.

    One other point to note, although this won't produce a syntax error, is that the "a subject line" entry was a placehold.... you can actually just use "-s Page Down" on the mail line, and the quotes aren't required, ie:

    Code:
    mail your-jayman228@verizon.net -s a  Page down </dev/null
    Again, this wouldn't produce your syntax error, just an e-mail with a subject line that wouldn't have been what you expected.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •