Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux redhat中的Perl和shell脚本_Linux_Bash_Perl_Jenkins - Fatal编程技术网

Linux redhat中的Perl和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

我对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/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_bts.ini是什么意思?如果不存在,是否需要显式创建这样的文件
  • 我猜perl脚本需要一个文件名作为它的第一个参数。shell脚本提供了这一点,它希望
    feed\u bts.ini
    文件位于
    $JENKINS\u HOME
    (另一个变量)目录中

  • 我是否需要将jenkins_feed.pl和feed_bts.ini保存在同一个目录中才能运行脚本
  • 由于
    cp
    ,jenkins\u feed.pl与shell脚本位于同一目录中。它以
    ~/cached resources/www.github.com/file1/executables/JenkinsScripts/jenkins\u feed.pl
    开头。请注意,
    ~
    将作为脚本运行的用户的主目录

  • perl脚本从哪个路径执行
  • 这可能会使用随发行版一起安装的任何库存perl。从技术上讲,shell将查看
    $PATH
    中的所有目录,直到找到它或目录用尽为止

    perl脚本分析
    • 第二个参数
      $Link\u A
      包含三条信息。在这个问题上,它被分成三个变量:
      $Link\u A、$skey、$priority

    • 这个函数的第一部分被填充回同一个命名变量中,该变量只在指定的时间使用。这看起来就像是出现在描述(
      $desc
      )中特定位置的任意文本,最终出现在Jenkins XML字段
      IV_description
    • $skey
      进入Jenkins XML字段
      IV_EVENT_KEY
      。这里有一个默认值,以防万一
    • $priority
      进入Jenkins XML字段
      IV_priority
    • 我没有找到任何方便的方法来定义这些字段的作用。它们是对“
      feed\u issue\u CREATION
      ”的SOAP调用的一部分

    • 脚本的第一个参数看起来像一个配置文件

    • 从命令行读取第一个参数。如果缺少,请转到
      用法
      子例程
    • 然后检查以确保它存在并且是一个文件。如果没有,请再次转到
      用法
      子例程
    • 使用配置文件名作为参数调用
      readopeninc
      子例程
    • 定义
      readopeninc
      子例程,它似乎可以做一些事情。它忽略以
      #
      作为绝对第一个字符开头的行。它会去除任何前导和尾随的空白。然后它假设您有类似shell的变量赋值:
      VAR\u NAME=SOME\u VALUE
    • 之后,它似乎将其中的值用作需要更新或关闭的作业
    • 基于此,看起来像是
      $inclog
      aka
      feed_INC.txt
      在某种程度上是相同的格式
    • 基于此,正在查找当前目录中的文件

    谢谢你这么好的解释。我这里有几个问题。1.链接是文件吗?2.feed_bts.ini是什么意思?如果不存在,是否需要显式创建这样的文件?3.我是否需要将jenkins_feed.pl和feed_bts.ini保存在同一个目录中才能运行脚本?4.perl脚本是从哪个路径执行的?非常感谢:-)@chicksCan如果可以,请帮助我使用perl脚本,因为我无法以正确的方式进行操作。这将是伟大的:-)请编辑最初的问题,包括源代码从脚本和任何具体的问题,你有关于它。我已经添加了源代码回购请你帮助这里谢谢@vipin kumar两个问题这里是链接_一种文件?什么是feed_bts.ini?那是一个文件吗?就内容而言,它是什么类型的文件?