4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Freedom2Support Pinging Project - PHP Help
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Mon Feb 02, 2004 4:47 pm (13 years, 10 months ago) Reply with QuoteBack to Top

I would do this manually normally, but don't just have enough hours in the day at the moment, so I want something basically like this.

I want a script to ping a particular F2S Customers home connection IP, and then come back with a value saying "Online" if it responds, or "Offline" if it doesn't respond.

You may ask why we're not using our service status script for this, but there are a few issues related to that, plus the fact we want a seperate ADSL Status.

It probbably only needs a simple bit of PHP code, but My abillity in PHP seems to have decreased of late, so any help would be appreciated.
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Mon Feb 02, 2004 6:49 pm (13 years, 10 months ago) Reply with QuoteBack to Top

n/m developed a script inhouse Smile
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Feb 02, 2004 7:15 pm (13 years, 10 months ago) Reply with QuoteBack to Top

Fancy sharing a snippet with us? Wink

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Mon Feb 02, 2004 7:53 pm (13 years, 10 months ago) Reply with QuoteBack to Top

Maybe in good time, but it's pretty basic at the moment, and isn't finished, but we have a working codebase, now just have to code a few features into it, such as at the moment it'll simply ping an IP and return a "Response Recieved" output or a "Fail" output.

What we want the final one to do is for it to attempt to ping the first IP for an ADSL Gateway, and if that works, give a Gateway Online output, but if not go on to another IP on the same gateway and trying all in a list and see if they respond, if not give a Gateway down output.

Then we wanna build caching into it so it'll probbably be a cron that runs the script every 10-15 minutes, save to a flat HTML file and be included into a page using php and be displayed on the F2Support website.

Of course there is still a lot of this to be done at the moment, so it may well not be finished for a few days/weeks yet, but it may get released into the community, as most of the inhouse developed stuff does, such as the safe mode uploader and the space calculater.

The script isn't wrote by me though, someone else on our team is developing it, and it'll be a bash script rather than php.


Last edited by Justin on Mon Feb 02, 2004 11:28 pm, edited 1 time in total
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Feb 02, 2004 8:04 pm (13 years, 10 months ago) Reply with QuoteBack to Top

I was just wondering how you were doing the bit which pings and can tell whether there's a response Wink (are you checking the output of the ping program?)

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Justin
4WebHelp Addict
4WebHelp Addict


Joined: 07 Jan 2002
Posts: 1060

PostPosted: Mon Feb 02, 2004 11:18 pm (13 years, 10 months ago) Reply with QuoteBack to Top

Bah, we're getting somewhere, you'll see the results in a few days, just have a small related question, how can I save the output of the bash script to a file?

I'm thinking If I knew how to do this, I could then run a cron every 10 minutes or so, then use a php include to include the status.

Any help appreciated.

Cheers
OfflineView User's ProfileFind all posts by JustinSend Personal MessageSend email
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Tue Feb 03, 2004 5:50 pm (13 years, 10 months ago) Reply with QuoteBack to Top

Well if the output of the script is saved to the variable $somecontent, use this code:
Code:
<?php
$filename = 'test.txt';

// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {

   // In our example we're opening $filename in append mode.
   // The file pointer is at the bottom of the file hence
   // that's where $somecontent will go when we fwrite() it.
   if (!$handle = fopen($filename, 'a')) {
         echo "Cannot open file ($filename)";
         exit;
   }

   // Write $somecontent to our opened file.
   if (!fwrite($handle, $somecontent)) {
       echo "Cannot write to file ($filename)";
       exit;
   }
 
   echo "Success, wrote ($somecontent) to file ($filename)";
 
   fclose($handle);
                 
} else {
   echo "The file $filename is not writable";
}
?>

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Peter
Team Member



Joined: 09 Jan 2002
Posts: 147
Location: UK

PostPosted: Tue Feb 03, 2004 6:41 pm (13 years, 10 months ago) Reply with QuoteBack to Top

Justin wrote:
how can I save the output of the bash script to a file?


Assuming bash script prints to stdout:
Code:
/path/to/script/in/crontab > /path/to/file.txt

will put all output in that file.

________________________________
Maple Design - quality web design and custom programming
OfflineView User's ProfileFind all posts by PeterSend Personal MessageVisit Poster's WebsiteYahoo MessengerICQ Number
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.092023 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme