我在hdfs中有一个shell命令,它在shell脚本中工作

2024-04-25 20:18:14 发布

您现在位置:Python中文网/ 问答频道 /正文

Shell脚本命令是: hadoop fs-ls/user/hive/warehouse/mashery_db.db/agg\u per\u mapi\u stats\u五分钟/|排序| awk'{if(index($8,“.hive”)==0&;$6<;=“'”delete \u up to \u epoch \u date“'”&;$7<;=“'”delete \u up to \u epoch_时间:00“'”)打印$8}' +str(日期从).zfill(2)+'*'


基本上我想在python脚本中执行。你知道吗


Tags: to命令lt脚本hadoopdbshelldelete
2条回答

https://pypi.python.org/pypi/python-hdfs/的伪ish

import pyhdfs
from operator import itemgetter

fs = pyhdfs.connect('hostname', 12345)

path = '/user/hive/warehouse/mashery_db.db/agg_per_mapi_stats_five_minutes/'

for f in sorted(fs.listdir(path), key=itemgetter('name')):
    # {kind, name, last_mod, size, replication, block_size, owner, group, permissions, last_access}
    is_hive = f['name'].endswith('.hive')
    is_old_enough = f['last_mod'] <= delete_up_to_in_right_format
    if is_hive and is_old_enough:
        print f['name']+str(date_from).zfill(2)+ '*'

我不太明白最后一个str(date_from).zfill(2)-这不是有效的shell

基本上你可以打开一个管道来执行你的命令。你知道吗

import os

p = os.popen("YOUR_COMMAND")

相关问题 更多 >