命令在linux命令行可以执行,但是在脚本中执行报错

lijie_cq 2017-05-30 02:28:13
想写一个比较规范的脚本,通过传递参数来用sqoop同步数据,通过参数的传递发现最后拼接的sqoop语句没有问题,日志打印出来可以直接复制粘贴到命令行上面执行,但是在脚本里面就是报错,说sqoop 参数问题,有人遇到类似的问题么


比如执行: ./main.sh MYSQL01_MYTEST_HIVE_TEXTFILE 1

日志最后打印出来---> sqoop语句:sqoop import --connect jdbc:mysql://192.168.80.123:3306/sqoop --username root --table MYTEST_HIVE --columns 'id,name,money,time_test_01,time_test_02,flag' --where 'time_test_02 >= 20170529 and time_test_02 < 20170530' --delete-target-dir --hive-overwrite --hive-import --hive-table lijie.MYSQL01_MYTEST_HIVE_TEXTFILE --fields-terminated-by '\001' -m 1

直接复制粘贴上面的到命令行执行没问题,但是在脚本中执行就报错,报错内容如下:
17/05/30 10:12:36 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Error parsing arguments for import:
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: >=
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: 20170529
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: and
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: time_test_02
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: <
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: 20170530'
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: --delete-target-dir
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: --hive-overwrite
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: --hive-import
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: --hive-table
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: lijie.MYSQL01_MYTEST_HIVE_TEXTFILE
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: --fields-terminated-by
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: '\001'
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: -m
17/05/30 10:12:36 ERROR tool.BaseSqoopTool: Unrecognized argument: 1

部分脚本:
#########################拼接sqoop语句##################--password ${8}
condition="'"${@:8}"'"
column="'"${2}"'"
sqoop_exec_str=" --connect ${1} --username ${6} --table ${3} --columns ${column} --where ${condition} --delete-target-dir --hive-overwrite --hive-import --hive-table ${4} --fields-terminated-by '\001' -m 1"

print_log "sqoop语句:sqoop import ${sqoop_exec_str}"

sqoop import ${sqoop_exec_str}

exit_exec $?



注:................. 上面的脚本都是通过vi编辑器编辑的

求各位大神解惑下,谢谢
...全文
1732 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lijie_cq 2017-05-30
  • 打赏
  • 举报
回复
暂时按照如下方式解决了,但是治标不治本 #########################拼接sqoop语句##################--password ${8} condition="\""${@:8}"\"" column="\""${2}"\"" sqoop_exec_str=" --connect ${1} --username ${6} --table ${3} --columns ${column} --where ${condition} --delete-target-dir --hive-overwrite --hive-import --hive-table ${4} --fields-terminated-by '\001' -m 1" print_log "sqoop语句:sqoop import ${sqoop_exec_str}" echo "sqoop import ${sqoop_exec_str}" > ${4}.sh chmod 777 ${4}.sh sh ${4}.sh exit_exec $? rm -rf ${4}.sh exit_exec $?

23,217

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧