具体代码如下>

import  paramiko,re,datetime,time
ssh=paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())              
ssh.connect(hostname="10.124.198.75",port=8122,username="admin",password='****',timeout=2)
stdin,stdout,stderr=ssh.exec_command("stat  /etc/passwd | grep Change")
stdin_sys,stdout_sys,stderr_sys=ssh.exec_command("date +%s")
change_time=re.search('Change: (.+)\\.',stdout.read().decode('utf-8')).group(1)
time1=datetime.datetime.strptime(change_time,"%Y-%m-%d %H:%M:%S")
change_time_new=str(time.mktime(time1.timetuple())).strip('.0')
sys_time=stdout_sys.read().decode('utf-8').strip()
time_stay=int(sys_time) - int(change_time_new)
print("距离上次更改:",datetime.timedelta(seconds=time_stay))
View Code

相关文章:

  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-09-19
猜你喜欢
  • 2022-12-23
  • 2021-12-26
  • 2021-12-11
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案