我有一个清单:
jos = ['/usr/bin/hive', '-e', "'set mapred.job.queue.name=exp_dsa; select * from trinity.clickstream where device_id = '59ab' and event_timestamp = '141833140000';'"]
我将像这样处理清单
cmdlines = " ".join(map(lambdas x:("'"+x+"'"), jos))
然后,我将在paramiko中推送此字符串:
stdin,stdout,stderr = ssh.exec_command(cmdlines)
paramiko所做的只是让我ssh
进入另一台机器。
我目前收到语法错误
stderr.readlines()
产生
[u"bash: -c: line 0: syntax error near unexpected token `from'\n", u"bash: -c: line 0: `'/usr/bin/hive' '-e' ''set mapred.job.queue.name=exp_dsa; select * from trinity.clickstream where application_mobile_device_id = '59ab' and event_timestamp = '141833140000';'''\n"]
不确定此错误的含义或需要修复的地方
初始化时jos
,我注意到您非常小心地使用"..."
而不是'...'
围绕包含的字符串'
。但是然后您在初始化时就放弃了这种谨慎cmdlines
:
cmdlines = " ".join(map(lambdas x:("'"+x+"'"), jos))
在这里,您只需将所有字符串包裹起来,'...'
并在它们之间放置空格。因此,您的实际Bash脚本(您对的实际参数bash -c
)为:
'/usr/bin/hive' '-e' ''set mapred.job.queue.name=exp_dsa; select * from trinity.clickstream where application_mobile_device_id = '59ab' and event_timestamp = '141833140000';''
当您真正需要的是:
'/usr/bin/hive' '-e' "set mapred.job.queue.name=exp_dsa; select * from trinity.clickstream where application_mobile_device_id = '59ab' and event_timestamp = '141833140000';"
甚至:
/usr/bin/hive -e "set mapred.job.queue.name=exp_dsa; select * from trinity.clickstream where application_mobile_device_id = '59ab' and event_timestamp = '141833140000';'"
(注意:我还删除了'
第三个字符串周围的一些-s。您已经"'...'"
在想要的位置上找到了"..."
。)
最好的解决方法可能是取消jos
阵列。不要对Bash脚本的胆量大打折扣。只需cmd_lines
直接设置:
cmd_lines = "/usr/bin/hive -e \"set mapred.job.queue.name=exp_dsa; select * from trinity.clickstream where application_mobile_device_id = '59ab' and event_timestamp = '141833140000';\""
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句