Using for loop to pass arguments to command

2019-08-16 01:55发布

I have below command that produce this output

Command:

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

Output:

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

I need to pass these output lines as input to below command along with storing the log file in /tmp folder

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

Trying to automated this with one single syntax using for loop but facing challenges. The current for loop that is having issue is below

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

Currently am getting error as below

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

Usually we will get this if we don't specify right applicationid as parameter.

0条回答
登录 后发表回答