使用for循环将参数传递给命令

时间:2017-09-22 20:35:01

标签: hadoop for-loop sh yarn

我有以下命令产生此输出

命令:

oozie job -info 0007218-170910003406158-oozie-oozi-W | grep job | awk '{print $3}' | cut -c1-23 | sed 's/job/application/'

输出:

application_1505017974932_23474
application_1505017974932_23478
application_1505017974932_23477
application_1505017974932_23473
application_1505017974932_23475
application_1505017974932_23471
application_1505017974932_23469
application_1505017974932_23476
application_1505017974932_23472
application_1505017974932_23470
application_1505017974932_23495
application_1505017974932_23497
application_1505017974932_23500
application_1505017974932_23501

我需要将这些输出行作为输入传递给下面的命令,同时将日志文件存储在/ tmp文件夹中

yarn logs -applicationId <applicationID> -Owner <userID> > /tmp/<applicationID>.txt

尝试使用for循环但面临挑战的单一语法自动执行此操作。有问题的当前for循环在

之下
for appid in `oozie job -info 0007218-170910003406158-oozie-oozi-W | grep job | awk '{print $3}' | cut -c4-23 | sed 's/job/application/'`; do yarn logs -applicationId "${appid}" -Owner user9 > /tmp/ "${appid}"; done

目前正在收到如下错误

Invalid ApplicationId specified
Invalid ApplicationId specified
Invalid ApplicationId specified
Invalid ApplicationId specified
Invalid ApplicationId specified

如果我们没有将正确的applicationid指定为参数,通常我们会得到这个。

0 个答案:

没有答案