每日一个小脚本

1、显示uid大于等于1000的用户

#!/usr/bin/env python

import re

with open('/etc/passwd','r') as f:

        for line in f:
                uid_list = re.split(':',line)
                uid = int(uid_list[2])
                if uid >= 1000:
                        print(uid_list[0])

 

 

 

 

 

 

 

 

 

 

 

2、显示当前网卡和ip:

ip add|grep inet |awk '{print$NF":\t"$2}'

 

3、用paramiko模块实现跳板机操作

需要先升级pip,然后安装paramiko模块

python3 -m pip install --upgrade pip

pip3 install paramiko

#!/usr/bin/env python
#-*- coding:UTF-8 -*-
import paramiko
#创建ssh对象
with paramiko.SSHClient() as client:

client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
hostname='192.168.27.71',
port = 22,
username='root',
password = 'Pass@w0rd'
)
with client.open_sftp() as sftp:
sftp.put("2021-01-06.log",'/2021-01-06.log') #源文件,目标文件
sftp.chmod('/2021-01-06.log',493) #755 -> -rwxr-xr-x -> 111101101 -> 493

#执行ls -l /操作并接受返回值
stdin, stdout, stderr = client.exec_command('ls -l /')

#将返回的信息转码
result = stdout.read().decode('utf-8')
print(result)


posted @ 2021-01-06 14:34  翎戍  阅读(103)  评论(0编辑  收藏  举报