【发布时间】:2019-12-06 07:00:07
【问题描述】:
我被我的代码卡住了,感谢您的帮助。这是我从詹金斯执行的一段代码。
#!/bin/bash
aws ec2 describe-instances --query 'Reservations[*].Instances[*].[Tags[?Key==`Name`].Value|[0],PrivateIpAddress]' --output text | column | grep devtools > devtools
ip=`awk '{print $2}' devtool`
echo $ip
ssh ubuntu@$ip -n "aws s3 cp s3://bucket/$userlistlocation . --region eu-central-1"
cd builds/${BUILD_NUMBER}/
scp * ubuntu@$ip:/home/ubuntu
if [ $port_type == "normal" ]; then
if [ $duplicate_value == "no" ]; then
if [ $userlist == "uuid" ]; then
ssh ubuntu@$ip -n "export thread_size='"'$thread_size'"'; filename=$(echo $userlistlocation | sed -E 's/.*\/(.*)$/\1/') ; echo $filename ; echo filename='"'$filename'"'; chmod +x uuidwithduplicate.sh; ./uuidwithduplicate.sh"
fi
fi
fi
fi
userlistlocation --> 是一个用户输入,它可以是任何格式 /rahul/december/file.csv 或者只是它可以是 file.csv。
通过 sed 命令,我可以获得输出并存储在“文件名”变量中。
但是当我尝试 echo $filename 它打印为 echo $filename 它应该打印为 file.csv
这个 file.csv 将是另一个要运行的脚本的源文件,即 uuidwithduplicate.sh
userlistlocation 和 thread_size 都是通过 Jenkins 作业参数指定的。
我在导出 thread_size 时没有遇到问题,唯一的问题是文件名。
它只是打印 echo $filename --> 它应该打印 file.csv
【问题讨论】:
-
在计算基本名称后执行
echo ull="$userlistlocation" bn="$fbname"。 -
总是引用文件名:
fbname=$( basename "$userlistlocation" )。但不确定,如果它在这里有帮助。