Example #1
0
def installed(package):
  """Confirm that a package is installed"""
  # TODO: Make this work with apt/dpkg
  try:
    return grepc(execute("yum list installed %s" % package), package) >0
  except Exception, _e:
    return False
Example #2
0
def running(processname):
  """Look for processname in the list of running processes"""
  try:
    return int(execute("ps wax | grep -v grep |  grep -c '%s'" % (processname))) > 0
  except Exception, e:
    # Pipeline exits nonzero if it doesn't find process, so return False
    # instead of letting the exception take out the test.
    return False
Example #3
0
def members(groupname):
    """Return the members of group groupname"""
    try:
        members = execute("getent group %s" % groupname).split(":")[3].strip().split(",")
        if members == [""]:
            return []
        else:
            return members
    except:
        return []
Example #4
0
def userCrontask(user, crontask):
  """Check that user has a specific entry in their crontab."""
  try:
    raw = execute("sudo crontab -u %s -l" % (user))
  except:
    return False
  if raw.find(crontask) >= 0:
    return True
  else:
    return False
Example #5
0
def hasRunLevel(serviceName, runLevel):
  """Parse chkconfig output and return True if serviceName is set to run at
  that runLevel"""
  try:
    raw = execute("chkconfig --list %s" % (serviceName)).split()
  except:
    # chkconfig will exit non-zero if there are no entries for serviceName
    return False
  for stanza in raw[1:]:
    level = int(stanza[:1])
    status = stanza[2:]
    if runLevel == level and status == "on":
      return True
  return False
Example #6
0
def shell(username):
  """Return username's shell"""
  try:
    return execute("getent passwd %s" % (username)).split(':')[6]
  except:
    return None
Example #7
0
def home(username):
  """Return username's home directory"""
  try:
    return execute("getent passwd %s" % (username)).split(':')[5]
  except:
    return None
Example #8
0
def gecos(username):
  """Return the gecos info for username"""
  try:
    return execute("getent passwd %s" % (username)).split(':')[4]
  except:
    return None
Example #9
0
def gid(username):
  """Return the gid for username"""
  try:
    return int(execute("getent passwd %s" % (username)).split(':')[3])
  except:
    return -1
Example #10
0
def exists(username):
  """Check if username exists"""
  try:
    return int(execute("getent passwd %s | wc -l" % (username))) > 0
  except:
    return False
Example #11
0
def gid(groupname):
    """Return the gid associated with group groupname"""
    try:
        return execute("getent group %s" % (groupname)).split(":")[2]
    except:
        return None
Example #12
0
def exists(groupname):
    """Return True if groupname exists on the system"""
    try:
        return int(execute("getent group %s | wc -l" % (groupname))) > 0
    except:
        return False
Example #13
0
def stdoutContains(command, required):
  """Run command, check for string required in the output"""
  try:
    return execute(command).find(required) >= 0
  except:
    return False