37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import pexpect
|
|
import argparse
|
|
import os
|
|
import tempfile
|
|
import sys
|
|
|
|
def space_check(ip, username, password,switchname):
|
|
#print(f"Checking {ip}")
|
|
#print(f"Logging in with {username} and {password}")
|
|
try:
|
|
child = pexpect.spawn(f"ssh -oHostKeyAlgorithms=+ssh-ed25519 {username}@{ip}")
|
|
#child.logfile = sys.stdout.buffer
|
|
child.expect("password:")
|
|
child.sendline(password)
|
|
child.expect("#")
|
|
child.sendline("start-shell")
|
|
child.expect('\$')
|
|
child.sendline("df -h /var/log")
|
|
child.expect('\$')
|
|
print(f"-------{switchname}--------")
|
|
print(child.before.decode("utf-8"))
|
|
child.sendline("exit")
|
|
child.expect("#")
|
|
except:
|
|
print("ERROR")
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="check /var/log free space")
|
|
parser.add_argument("--username", help="Username for login", required=True)
|
|
parser.add_argument("--password", help="Password for login", required=True)
|
|
parser.add_argument("--ip", help="IP address of switch", required=True)
|
|
parser.add_argument("--switchname", help="switch name", required=True)
|
|
|
|
args = parser.parse_args()
|
|
|
|
space_check(args.ip, args.username, args.password,args.switchname)
|