-
Notifications
You must be signed in to change notification settings - Fork 1
/
folder_files.py
41 lines (32 loc) · 979 Bytes
/
folder_files.py
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
#! /usr/bin/python3
# https://github.com/saulotarsobc/zabbix-monitoramento-arquivos
# https://t.me/saulos2costa
import os
import regex
import sys
import platform
import json
if len(sys.argv) != 3:
exit('script <diretorio> <extensao>')
if platform.system() == "Linux":
pattern = '.*\s.*\s.*\s+.*\s+([0-9]+)\s+([0-9]+)\s(.*)'
else:
pattern = '.*\s.*\s.*\s[0-9]+\s+([0-9]+)\s([0-9]+)\s(.*)'
def getDirList(diretorio, extensao):
final = []
comando = "ls {} -ltr --time-style='+%s' | grep {}".format(
diretorio, extensao)
res = os.popen(comando).read()
for row in res.split('\n'):
if row:
iSplited = (regex.split(pattern, row))
final.append({
'{#SIZE}': iSplited[1],
'{#UPTIME}': iSplited[2],
'{#NAME}': iSplited[3],
})
return final
def main():
print(json.dumps(getDirList(sys.argv[1], sys.argv[2])))
if __name__ == "__main__":
main()