Linux redhat中的Perl和shell脚本
我对Perl、Linux和shell脚本非常陌生。有人能告诉我这段脚本到底在做什么吗?我在网上搜索过,找不到答案Linux redhat中的Perl和shell脚本,linux,bash,perl,jenkins,Linux,Bash,Perl,Jenkins,我对Perl、Linux和shell脚本非常陌生。有人能告诉我这段脚本到底在做什么吗?我在网上搜索过,找不到答案 #!/bin/bash set +xe if [ x"$Link_A" == "x" ] ; then echo "Link_A parameter not set, DOESNOT execute FUNCTION" else cp -f ~/cached-resources/www.github.com/file1/executables/JenkinsScripts/jenk
#!/bin/bash
set +xe
if [ x"$Link_A" == "x" ] ; then
echo "Link_A parameter not set, DOESNOT execute FUNCTION"
else
cp -f ~/cached-resources/www.github.com/file1/executables/JenkinsScripts/jenkins_feed.pl ./jenkins_feed.pl
perl jenkins_feed.pl $JENKINS_HOME/feed_config.ini $Link_A
fi
感谢您的帮助
我用Perl添加了源代码,并编辑了shell参数名称。
要使这个Perl文件运行,我需要在系统路径中更改、追加或放置什么
源代码:请参见下文,以了解脚本的逐行使用-
#!/bin/bash #### Used to set the type of script "bash"
set +xe #### Used to execute the script in debug mode (set +x) and e is used to receive the input from terminal
if [ x"$Link_A" == "x" ] ; then ##### condition check if x appending something is equal to x means no value in variable LinK_A
echo "Link_A parameter not set, DOESNOT execute FUNCTION" ##### print this line if above condition is true
else ###### if above condition is not true do below operation
cp -f ~/cached-resources/www.github.com/file1/executables/JenkinsScripts/jenkins_feed.pl ./jenkins_feed.pl
#####above line copy the file jenkis_feed.pl from specified directory to current dir forcefully
perl jenkins_feed.pl $JENKINS_HOME/feed_bts.ini $Link_A #### execute jenkil program which take two input parameter
fi
下面是另一种解释:
#!/bin/bash
# enable debug
set +xe
# this is an old school way to check for an empty variable
# modern shells can use [[ $foo == "" ]] to do this
if [ x"$Link_A" == "x" ] ; then
# a normal error message for when the variable is not set
echo "Link_A parameter not set, DOESNOT execute FUNCTION"
else # the variable has a value so we can use it...
# copy this file to the current directory
cp -f ~/cached-resources/www.github.com/file1/executables/JenkinsScripts/jenkins_feed.pl ./jenkins_feed.pl
# run the script in perl with arguments that include variable
# substitution and some fixed text
perl jenkins_feed.pl $JENKINS_HOME/feed_bts.ini $Link_A
fi
我还重新格式化了脚本,使条件的内部部分缩进
评论中的奖励问题
Link-A
是一个变量。变量可以指向文件或目录,但不清楚在这种情况下该变量将包含什么。检查perl
脚本对于明确回答这个问题是必要的
feed\u bts.ini
文件位于$JENKINS\u HOME
(另一个变量)目录中
cp
,jenkins\u feed.pl与shell脚本位于同一目录中。它以~/cached resources/www.github.com/file1/executables/JenkinsScripts/jenkins\u feed.pl
开头。请注意,~
将作为脚本运行的用户的主目录
$PATH
中的所有目录,直到找到它或目录用尽为止
perl脚本分析
- 第二个参数
包含三条信息。在这个问题上,它被分成三个变量:$Link\u A
$Link\u A、$skey、$priority
- 这个函数的第一部分被填充回同一个命名变量中,该变量只在指定的时间使用。这看起来就像是出现在描述(
)中特定位置的任意文本,最终出现在Jenkins XML字段$desc
IV_description
进入Jenkins XML字段$skey
。这里有一个默认值,以防万一李>IV_EVENT_KEY
进入Jenkins XML字段$priority
IV_priority
- 我没有找到任何方便的方法来定义这些字段的作用。它们是对“
”的SOAP调用的一部分feed\u issue\u CREATION
- 脚本的第一个参数看起来像一个配置文件
- 从命令行读取第一个参数。如果缺少,请转到
子例程李>用法
- 然后检查以确保它存在并且是一个文件。如果没有,请再次转到
子例程李>用法
- 使用配置文件名作为参数调用
子例程readopeninc
- 定义
子例程,它似乎可以做一些事情。它忽略以readopeninc
作为绝对第一个字符开头的行。它会去除任何前导和尾随的空白。然后它假设您有类似shell的变量赋值:#
VAR\u NAME=SOME\u VALUE
- 之后,它似乎将其中的值用作需要更新或关闭的作业
- 基于此,看起来像是
aka$inclog
在某种程度上是相同的格式feed_INC.txt
- 基于此,正在查找当前目录中的文件