# $Id$
import time
import os
-import commands
from pprint import PrettyPrinter
# how could this accept a list again ?
print "+",now,':',command
return os.system("set -x; " + command)
-# checks whether a given hostname/ip responds to ping
-ping_timeout_option = None
-def check_ping (hostname):
- # check OS (support for macos)
- global ping_timeout_option
- if not ping_timeout_option:
- (status,osname) = commands.getstatusoutput("uname -s")
- if status != 0:
- raise Exception, "Cannot figure your OS name"
- if osname == "Linux":
- ping_timeout_option="-w"
- elif osname == "Darwin":
- ping_timeout_option="-t"
- command="ping -c 1 %s 1 %s"%(ping_timeout_option,hostname)
- (status,output) = commands.getstatusoutput(command)
- return status == 0
-
-# inserts a backslash before each occurence of the following chars
-# \ " ' < > & | ; ( ) $ * ~
-def backslash_shell_specials (command):
- result=''
- for char in command:
- if char in "\\\"'<>&|;()$*~":
- result +='\\'+char
- else:
- result +=char
- return result
-
-# check main IP address against the provided hostname
-def is_local (hostname):
- if hostname == "localhost":
- return True
- import socket
- local_ip = socket.gethostbyname(socket.gethostname())
- remote_ip = socket.gethostbyname(hostname)
- return local_ip==remote_ip
+