简体   繁体   English

如何在 EMR 上运行的 Bash 脚本中“获取”另一个文件

[英]How to 'source' another file in a Bash script run on EMR

Is there a way when running a step in AWS EMR to 'source' another file in a bash script?在 AWS EMR 中运行一个步骤以在 bash 脚本中“获取”另一个文件时,有没有办法?

For example, this is a script, let's call it 'run.sh':例如,这是一个脚本,我们称它为“run.sh”:

#!/bin/sh
source $1
echo $VAR1" "$VAR2
exit0

Then have another file, call it 'parms.sh':然后有另一个文件,称之为“parms.sh”:

VAR1=this
VAR2=that

Then run from AWS EMR step:然后从 AWS EMR 步骤运行:

aws emr add-steps \
--cluster-id 123 \
--steps Type=CUSTOM_JAR,\
Name="Script Test",\
ActionOnFailure=CONTINUE,\
Jar=s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar,\
Args=[s3://mybucket/run.sh,"s3://mybucket/parms.sh"]

This error exits as soon as it hits the 'source' statement.一旦遇到“源”语句,此错误就会退出。 I assume it can't 'source' from S3 for some reason?我认为由于某种原因它不能从 S3“获取”?

So sourcing from S3 can't work, which I suppose make sense on some level.所以从 S3 采购是行不通的,我认为这在某种程度上是有道理的。 Looked a little closer at EMR docs, and it seems the solution is to copy both files to somewhere on the cluster as part of the step then execute:仔细查看 EMR 文档,似乎解决方案是将这两个文件复制到集群上的某个位置,作为步骤的一部分,然后执行:

aws emr add-steps \
--cluster-id 123 \
--steps Type=CUSTOM_JAR,\
Name="Script Test",\
ActionOnFailure=CONTINUE,\
Jar=s3://us-east-1.elasticmapreduce/libs/script-runner/script-runner.jar,\
Args=[/usr/bin/bash,-c,"aws s3 cp s3://mybucket/run.sh /home/hadoop; \
aws s3 cp s3://mybucket/parms.sh /home/hadoop; 
/usr/bin/chmod u+x /home/hadoop/run.sh; \
/usr/bin/chmod u+x /home/hadoop/parms.sh; \
cd /home/hadoop; 
./run.sh ./parms.sh"] 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 bash 命令将 EMR 步骤添加到 cloudformation - How to add EMR step with bash command to cloudformation 如何在 AWS CloudFormation 模板中运行 bash 脚本 - How to run a bash script in a AWS CloudFormation template EMR - Airflow 运行 scala jar 文件 airflow.exceptions.AirflowException - EMR - Airflow to run scala jar file airflow.exceptions.AirflowException 如何在 AWS EMR 启动后添加 shell 脚本 - How to add a shell script after AWS EMR has started 如何使用 boto3 运行现有的 EMR 无服务器作业? - How to run existing EMR serverless job with boto3? Bash 脚本设置环境变量在使用源时不起作用,仅适用于 bash -c - Bash script to set env variables does not work when using source and only works with bash -c 在 AzureDevops 中,尝试运行一个 yaml 文件来触发一个 powershell 脚本——我如何为脚本分配不同的环境值 - In AzureDevops , trying to run a yaml file to trigger a powershell script - how can i assign different environment values to script 通过传递凭据在 AWS EMR 上运行 spark - run spark on AWS EMR by passing credentials 如何将这个 Bash 脚本转换为 PowerShell - How to convert this Bash script to PowerShell 如何在 terraform 中注入带有美元符号 ($) 的 bash 脚本? - How to inject a bash script with a dollar sign ($) in terraform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM