用了一个杀毒软件的更新工具,不过它不会自动删除过时的。然后用刚学的python折腾了一个。。。
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
|
#!/usr/bin/python
import
os
import
shutil
xxx_dir
=
"/var/www/xxx/rel"
tmp_dir
=
{}
#run update
os.system(
'sh /etc/xxx/start.sh'
)
for
i
in
os.listdir(xxx_dir):
tmp
=
i.split(
'_'
)
tmp_key
=
"_"
.join(tmp[:
-
1
])
if
tmp_dir.has_key(tmp_key):
#exist key value
if
int
(tmp_dir[tmp_key]) <
int
(tmp[
-
1
]):
#shutil.rmtree 可以直接删除目录
shutil.rmtree(xxx_dir
+
"/"
+
tmp_key
+
"_"
+
tmp_dir[tmp_key])
tmp_dir[tmp_key]
=
tmp[
-
1
]
else
:
shutil.rmtree(xxx_dir
+
"/"
+
tmp_key
+
"_"
+
tmp[
-
1
])
else
:
tmp_dir[tmp_key]
=
tmp[
-
1
]
print
"Update OK"
|
上面那个是用另一个工具更新时用的, 那个现在不好用了,又换了一个服务器. 然后再折腾一个脚本.
本来不想折腾,不过杀毒软件用相关许可去更新时会进程卡死,奇怪. 于是这样折腾了...
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
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/usr/bin/env python
import
urllib
import
hashlib
import
os
import
sys
import
time
www
=
"C:\\Python27\\nod32\\"
ser
=
"http://user:pass@update.com/"
num
=
0
def
reporthook(count, block_size, total_size):
#下载进度
global
start_time
if
count
=
=
0
:
start_time
=
time.time()
return
duration
=
time.time()
-
start_time
progress_size
=
int
(count
*
block_size)
speed
=
int
(progress_size
/
(
1024
*
duration))
percent
=
int
(count
*
block_size
*
100
/
total_size)
if
percent >
100
: percent
=
100
sys.stdout.write(
"\r...%d%%, %d KB, %d KB/s, %d seconds passed, Filesize %d KB"
%
(percent, progress_size
/
1024
, speed, duration, total_size
/
1024
))
sys.stdout.flush()
def
download(u, f, n):
try
:
print
"\n"
,n,os.sep.join(f.split(os.sep)[
-
2
:])
urllib.urlretrieve(u, f, reporthook)
except
:
print
"Download %s Failed"
%
os.sep.join(f.split(os.sep)[
-
2
:])
sys.exit(
1
)
# cb54b290a1a825b29403f7ad285837b4 /var/www/html/v4-rel-sta/mod_008_epfw/em008_64_n3.nup
if
__name__
=
=
"__main__"
:
download(ser
+
"nod32.md5"
, www
+
"nod32.md5"
,
0
)
if
os.path.isfile(www
+
"nod32.md5"
):
with
open
(www
+
"nod32.md5"
) as f:
for
i
in
f:
num
+
=
1
if
"/var/www/html"
not
in
i:
continue
md5, url, filename, dirname
=
i.split()[
0
], ser
+
"/"
.join(i.split()[
1
].split(
"/"
)[
4
:]), www
+
os.sep.join(i.split()[
1
].split(
"/"
)[
4
:]), www
+
os.sep.join(i.split()[
1
].split(
"/"
)[
4
:
-
1
])
if
not
os.path.isdir(dirname):
os.makedirs(dirname)
if
os.path.isfile(filename):
# 查文件md5时,读文件要用 rb 模式
with
open
(filename,
"rb"
) as n:
if
hashlib.md5(n.read()).hexdigest() !
=
md5:
download(url, filename, num)
else
:
download(url, filename, num)
|
另外:rsync 时 ssh端口不是22
1
|
rsync
-az --progress
'-e ssh -p 1234'
/var/www/html/
* 1.2.3.4:
/home/nod32/
|
本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1582886,如需转载请自行联系原作者