Sponsored Content
Full Discussion: Ping test using python
Top Forums Shell Programming and Scripting Ping test using python Post 302961161 by Aia on Tuesday 24th of November 2015 02:46:34 PM
Old 11-24-2015
subprocess is the module intended to be used instead of os.system

Maybe this might help:

Code:
import subprocess
import sys

host = 'myclient'
cmd = ['ping', '-c2', '-W 5', host ]
done = False
timeout = 10 # default time out after ten times, set to -1 to disable timeout

print "Rebooting .",
while not done and timeout:
        response = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        stdout, stderr = response.communicate()
        if response.returncode == 0:
            print "Server up!"
            done = True
        else:
            sys.stdout.write('.')
            timeout -= 1
if not done:
       print "\nServer failed to respond"


Last edited by Aia; 11-24-2015 at 04:06 PM.. Reason: Adds prints to accomodate OP output
This User Gave Thanks to Aia For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help: infinant loop script - host ping test

need to check on some hosts and send an email if there status changes I wanna put together a script in bash that will allow me to check the up/down state of a single host via ping i want it to run in a continuous loop so I can just fire the script and forget about it(dont want cron to drive... (2 Replies)
Discussion started by: zeekblack
2 Replies

2. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

3. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

4. Programming

python little ping script

Hi everyone, I'm a newby in the python languages, and I try to make some parallels to shell. My question is how ca I give the information to python that the line 3 "r=...." the string "line" is a variable. import os, re line = "localhost" r = "".join(os.popen("ping line -c... (2 Replies)
Discussion started by: research3
2 Replies

5. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

6. Shell Programming and Scripting

python test datetime 30 minutes ago

Hello, RHEL5.5 PYTHON=2.4.3 I have 2 python variables using the datetime module. Here is how I call them: print "Current Time: %s" % now print "LastDownloadTime: %s" % LastDownloadTime Here is an example of an issue. Current Time: 2012-01-05 14:06:09.749240... (2 Replies)
Discussion started by: jaysunn
2 Replies

7. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

8. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

9. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
wbemexec(1)															       wbemexec(1)

NAME
wbemexec - submit a CIM operation request to a CIM Server SYNOPSIS
wbemexec [ -h hostname ] [ -p portnumber ] [ -v httpversion ] [ -m httpmethod ] [ -t timeout ] [ -u username ] [ -w password ] [ -s ] [ --help ] [ --version ] [ inputfilepath ] DESCRIPTION
The wbemexec command provides a command line interface to a CIM Server. The input to the command consists of a CIM request encoded in XML. The request is submitted to the CIM Server for execution. If the HTTP response from the CIM Server contains a status code of 200 (OK), the result returned to stdout is the CIM response encoded in XML. Otherwise, the result returned to stdout is the HTTP response. Some types of invalid XML requests (e.g. missing PROTOCOLVERSION attribute or missing NAME attribute) are detected by wbemexec, and result in an error message from wbemexec. Other invalid XML requests (e.g. invalid CIMVERSION attribute value or missing XML version), are detected by the CIM Server, and result in an HTTP response, containing a non-Success status code, such as 501 (Not Implemented) or 400 (Bad Request). By default, the request is sent as an HTTP/1.1 request, using the HTTP M-POST method, and wbemexec waits 20000 milliseconds (20 seconds), then times out if a response hasn't been received. Input is read from stdin, if no input file is specified. By default, the operation is executed on the local host. wbemexec first attempts to connect to the CIM Server on the default port for the wbem-http service, and if that fails, another attempt is made on the default port for the wbem-https service. Options wbemexec recognizes the following options: -h hostname Connect to the CIM Server on the specified host. If this option is not specified, wbemexec connects to the local host. --help Display command usage information. -m httpmethod Use the specified HTTP method for the request. The method must be "POST" or "M-POST". -p portnumber Connect to the CIM Server on the specified port number. If this option is not specified, wbemexec connects to the default port for the wbem-http service, or if the -s option is specified, to the default port for the wbem-https ser- vice. -s Enable the use of the SSL protocol between and the CIM server. The -s option should be specified if the CIM Server on the specified hostname/portnumber expects clients to connect using HTTPS. -t timeout Wait the specified number of milliseconds on sending a request, before timing out if no response has been received. The timeout value must be an integer value greater than 0. -u username Connect as the specified R username . If username is not specified, the current logged in user is used for authenti- cation. This option is ignored if neither hostname nor portnumber is specified. -v httpversion Use the specified HTTP version for the request. The version must be "1.0" or "1.1". The 1.0 version may not be specified if the M-POST method is specified. --version Display CIM Server version. -w password Authenticate the connection using the specified password . This option is ignored if neither hostname nor portnumber is specified. WARNING: A password should not be specified on the command line on a multi-user system, since command- line options are typically world-readable for a short window of time. If the remote host requests authentication and this option is not specified, wbemexec will prompt for the password. (See cimconfig (1) for information on configur- ing the CIM Server.) EXIT STATUS
When an error occurs, an explanatory error message is written to stderr and an appropriate value is returned. The following exit values are returned: 0 Success 1 Error USAGE NOTE
The wbemexec command requires that the CIM Server is running. EXAMPLES
Submit an XML request contained in the file cimrequest.xml to the CIM Server running on the local host on the default port: wbemexec cimrequest.xml Submit an XML request contained in the file cimrequest.xml to the CIM Server running on the host hpserver on port 49152, using the username guest and password guest for authentication: wbemexec -h hpserver -p 49152 -u guest -w guest cimrequest.xml SEE ALSO
cimserver(1), cimconfig(1). STANDARDS CONFORMANCE
wbemexec: CIM Operations over HTTP 1.0, Representation of CIM in XML 2.0 wbemexec(1)
All times are GMT -4. The time now is 09:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy