0%

该脚本可以查找某个目录里指定时间范围的文件,并保存目录结构复制到新的路径。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import os
import shutil
import time

time0 = "2021-01-27"#起始日期
time1 = "2021-03-02"#结束日期
targetDir = r"/home/backup"#目标目录
print("正在处理,请稍等.....")
curDir = r"/home/flask"#原来的路径
for root, dirs, files in os.walk(curDir):
#先创建目标目录
curFolder = root[len(curDir)+1:] #提取当前文件夹
tempTargetDir = os.path.join(targetDir, curFolder) #生成目标目录绝对路径
# print(tempTargetDir)
if os.path.exists(tempTargetDir):
shutil.rmtree(tempTargetDir)
#再拷贝文件
t0 = time.mktime(time.strptime(time0, "%Y-%m-%d"))
t1 = time.mktime(time.strptime(time1, "%Y-%m-%d"))+3600*24
for fileName in files:
absFileName = os.path.join(root, fileName)
if os.path.splitext(absFileName)[1] != '.py' and os.path.getmtime(absFileName) >= t0 and os.path.getmtime(absFileName) <= t1:
if not os.path.exists(tempTargetDir):
os.makedirs(tempTargetDir)
print("正在拷贝文件:", absFileName)
shutil.copy(absFileName, tempTargetDir)

推荐python3运行。

安装oracle的服务器这三个目录千万别删。

1
2
3
/tmp
/usr/tmp
/var/tmp

里面可能存在.oracle目录。

删除会导致oracle监听失败。

需要重建该目录。

1
2
mkdir /var/tmp/.oracle
chown -R oracle:oinstall /var/tmp/.oracle

重启oracle并重启监听。

可以测试到某个服务器的某个端口的连通性。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python
#-*-coding:GBK -*-

import socket,sys,time,os,signal
from ping3 import ping
result = []
def Seeyon_write(result):
filename = 'result.txt'
with open(filename, 'a+') as file_object:
file_object.write(str(time.asctime( time.localtime(time.time()) ))+result)
file_object.close()
def Seeyon_Con():
Seeyon_sk=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
Seeyon_Result=Seeyon_sk.connect_ex(('59.197.224.47',80))
if Seeyon_Result == 0:
Seeyon_write(' Port is Open! \n')
print(str(time.asctime( time.localtime(time.time()) ))+' Port is Open!')
result.append('1')
else:
Seeyon_write(' Port is Not Open! \n')
print(str(time.asctime( time.localtime(time.time()) ))+' Port is Open!')
result.append('2')
def Seeyon_exit(signum, frame):
Seeyon_write('成功:'+str(result.count('1'))+' '+'失败:'+str(result.count('2')) +'\n')
print(' 成功:'+str(result.count('1'))+' '+'失败:'+str(result.count('2')))
sys.exit(0)
def Seeyon_ping(ip_address):
response = ping(ip_address)
if response is not None:
delay = int(response * 1000)
Seeyon_write('连接延时:'+str(delay)+'\n')
print ('连接延时:'+str(delay)+'\n')
if __name__ == '__main__':
print ('\n开始测试本机到59.197.224.47的80端口的连通性:\n')
signal.signal(signal.SIGINT, Seeyon_exit)
signal.signal(signal.SIGTERM, Seeyon_exit)
while True:
Seeyon_Con()
Seeyon_ping('59.197.224.47')
time.sleep(3)

推荐python3运行。