bash +运行cli以运行来自用户hdfs的命令

时间:2019-10-27 15:38:27

标签: linux bash hadoop hdfs

我的bash脚本中有以下几行内容,以便修复HDFS中的复制文件

参考-https://community.cloudera.com/t5/Community-Articles/Fix-Under-replicated-blocks-in-HDFS-manually/ta-p/244746

  su hdfs -c "hdfs fsck / | grep 'Under replicated' | awk -F':' '{print \$1}' > /tmp/under_replicated_files"

  su hdfs -c "for hdfsfile in `cat /tmp/under_replicated_files`; do echo "Fixing $hdfsfile :" ;  hadoop fs -setrep 3 $hdfsfile; done"

脚本运行失败

: ;  hadoop fs -setrep 3 ; done: -c: line 1: syntax error near unexpected token `/user/ambari-qa/.staging/job_1571913174208_0001/job.split'
: ;  hadoop fs -setrep 3 ; done: -c: line 1: `/user/ambari-qa/.staging/job_1571913174208_0001/job.split'

文件/tmp/under_replicated_files包含:

/user/ambari-qa/.staging/job_1571913174208_0001/job.jar
/user/ambari-qa/.staging/job_1571913174208_0001/job.split
/user/ambari-qa/.staging/job_1571913174208_0003/job.jar

我在以下行中错了吗?

  su hdfs -c "for hdfsfile in `cat /tmp/under_replicated_files`; do echo "Fixing $hdfsfile :" ;  hadoop fs -setrep 3 $hdfsfile; done"

注意:

当我执行用户-hdfs的相同步骤的步骤时,我们没有任何问题

示例:

su hdfs

$ hdfs fsck / | grep 'Under replicated' | awk -F':' '{print $1}' > /tmp/under_replicated_files
$ for hdfsfile in `cat /tmp/under_replicated_files`; do echo "Fixing $hdfsfile :" ;  hadoop fs -setrep 3 $hdfsfile; done

我们也尝试过

su hdfs -c "for hdfsfile in `cat /tmp/under_replicated_files`; do echo \"Fixing $hdfsfile :\" ;  hadoop fs -setrep 3 $hdfsfile; done"

但我们得到:

bash: -c: line 1: syntax error near unexpected token `/user/ambari-qa/.staging/job_1571913174208_0001/job.split'
bash: -c: line 1: `/user/ambari-qa/.staging/job_1571913174208_0001/job.split'

0 个答案:

没有答案