how to know server is down


 
Thread Tools Search this Thread
Special Forums IP Networking how to know server is down
# 1  
Old 03-07-2007
how to know server is down

hi all
this is the code to know wether the net on or off


#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>

int can_resolve_host (const char *host)
{
struct hostent *h = NULL;
h = gethostbyname (host);

if (h == NULL)
{
return -1;
}
else
{
return 0;
}
}

int netstate()
{
FILE* FD;
char buf[256] = {0};
char* linkstatus = NULL;

FD = popen ("/sbin/mii-tool", "r");

if (FD)
{
fgets (buf, sizeof (buf), FD);
buf[strlen(buf) - 1] = '\0';
linkstatus = strstr (buf, "ok");
}

pclose (FD);
if ((linkstatus) && (0 == strcmp (linkstatus, "ok")))
{
if (can_resolve_host ("axillsearch.com") == -1)
{
printf ("Failed to reach axillsearch.com\n");
}
else
{
printf ("Successfully reached axillsearch.com\n");
}
}
else
fprintf (stderr, "%s(): Network connectivity not available \n", __func__);
printf ("U r net is down \n");
return -1;

}

int
main (int argc, char *argv[])

{

int i;
i=gtk_timeout_add(8000,
(GtkFunction) netstate,
NULL);

gtk_main ();
return 0;
}
save it has one.c
and compile
gcc one.c -o one `pkg-config gtk+-2.0 --cflags --libs`


it is working successfully
when
1.net deactivate or activate
2.cable unplugged or plugged

but it is not working when the server is down

how can i do when the server is down

when the serveris down(main servers)
it has to show the message like
"U r net is down \n"

if any help
cheers
# 2  
Old 03-07-2007
what meaning do you put "when the server is down" ? Machine is shutted down ? Do you have any requirement on which language to write this ? Does it has to be application/deamon or shell script ran via crontab ? Shed some light please.
# 3  
Old 03-08-2007
hi

thank for your replay

its a daemon prosess
i wanna run the program continuosly.

it is working fine.

but when the server is down it is taking some time.

why dont you run the program once, so that you can know.
i think you understand my problem.

please help me.
# 4  
Old 03-28-2007
i think u can use ping utility

ping -c2 ip_address
and check the status of the ping command by echo $?
if 0 echoed then server is alive otherwise server is down

rest u can check man ping
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Transfer file from server B to server C and running the script on server A

I have 3 servers A, B, C and server B is having some files in /u01/soa/ directory, these files i want to copy to server C, and i want to run the script from server A. Script(Server A) --> Files at Server B (Source server) --> Copy the files to Server C(Target Server). We dont have RSA key... (4 Replies)
Discussion started by: kiran_j
4 Replies

2. Shell Programming and Scripting

Shell script to copy a file from one server to anther server and execute the binary

Hi , Is there any script to copy a files (weblogic bianary + silent.xml ) from one server (linux) to another servers and then execute the copy file. We want to copy a file on multiple servers and run the installation. Thanks (1 Reply)
Discussion started by: Nawrajesh
1 Replies

3. Shell Programming and Scripting

Connect to server-1 from server-2 and get a file from server-1

I need to connect to a ftp server-1 from linux server-2 and copy/get a file from server-1 which follows a name pattern of FILENAME* (located on the root directory) and copy on a directory on server-2. Later, I have to use this file for ETL loading... For this I tried using as below /usr/bin/ftp... (8 Replies)
Discussion started by: dhruuv369
8 Replies

4. Shell Programming and Scripting

KSH fetching files from server A onto server B and putting on server C

Dear Friends, Sorry for this basic request. But I just started learning Ksh recently and still I am a newbie in this field. Q: I have files on one server and the date format is 20121001000009_224625.in which has year (yyyy) month (mm) and date (dd). I have these files on server A. The task... (8 Replies)
Discussion started by: BrownBob
8 Replies

5. UNIX for Dummies Questions & Answers

Access of Microsoft Team Foundation Server (TFS) repository from Unix Server

Hello, Some of our application team uses Microsoft Team Foundation server (TFS) reposity tool for their .NET projects , I would like to access it form Unix/Linux machine. Please let me know how can access the TFS from unix. Thanks (0 Replies)
Discussion started by: posix
0 Replies

6. Programming

Problem with Perl script after moving from a Windows/Apache Server to a UNIX server.

I have a Perl script that worked fine before moving it to justhost.com. It was on a Windows/Apache server. Just host is using UNIX. Other Perl scripts on other sites that were also moved work fine so I know Perl is functioning. The script is called cwrmail.pl and is located in my cgi-bin. When I... (9 Replies)
Discussion started by: BigBobbyB
9 Replies

7. Windows & DOS: Issues & Discussions

Office server => laptop =>client server ...a lengthy and laborious ftp procedure

Hi All, I need your expertise in finding a way to solve my problem.Please excuse if this is not the right forum to ask this question and guide me to the correct forum,if possible. I am a DBA and on a daily basis i have to ftp huge dump files from my company server to my laptop and then... (3 Replies)
Discussion started by: kunwar
3 Replies

8. Red Hat

when users ftp to server the timezone reflected is UTC but the server is set to TZ in localtime

Guys, Need your help coz my server runs in local time GMT +8, but when client use ftp and login, the resulting timestamp seen in each file is in UTC format. We need to set that the time should be the same as GMT +8 when in ftp session. I am using RHEL 5.3. root@]# ll total 1740... (2 Replies)
Discussion started by: shtobias
2 Replies

9. Shell Programming and Scripting

preserving the timestamp of a file when copied from remote server to local server using ftp

Hi, I need to copy few files from remote server to local server. I write a shell script to connect to the remote server using ftp and go to that path. Now i need to copy those files in the remote directory to my local server with the timestamp of all those files shouldnt be changed. ... (5 Replies)
Discussion started by: arunkumarmc
5 Replies
Login or Register to Ask a Question