1

I am pretty new to Perl, Linux and shell scripts. Can anybody let me know what exactly is this piece of script doing? I have searched through internet and couldn't find answer.

#!/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

Any help is appreciated.

I added the source code in Perl and edited the shell parameter names too. What do I need to change or append or place in system path to make this Perl file run.

Source code: https://github.com/rebeccaus/perl/blob/master/feed.pl

2 Answers 2

1

Here's another explanation:

#!/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

I also reformatted the script so the inner parts of the conditional are indented.

bonus questions from comments

  1. Is Link_A a file ?

Link-A is a variable. A variable could point to a file or directory, but it isn't clear what the variable would contain in this case. Examining the perl script would be necessary to answer this definitively.

  1. what does feed_bts.ini means do i need to create a file like this explicitly if not present?

I'd guess the perl script is expecting a file name as its first argument. The shell script provides this and it expects the feed_bts.ini file to be in the $JENKINS_HOME (another variable) directory.

  1. Do I need to keep the jenkins_feed.pl and feed_bts.ini in same directory to run the script?

The jenkins_feed.pl ends up in the same directory as the shell script because of the cp. It starts as ~/cached-resources/www.github.com/file1/executables/JenkinsScripts/jenkins_feed.pl. Note that ~ would the home directory of the user the script runs as.

  1. from which path is the perl script executing

This would probably be using whatever the stock perl installed with your distro is. Technically the shell will look through all of the directories in your $PATH until it finds it or runs out of directories.

perl script analysis

Sign up to request clarification or add additional context in comments.

7 Comments

thanks for such a nice explanation. I have few questions here. 1. Is Link_A a file ? 2. what does feed_bts.ini means do i need to create a file like this explicitly if not present? 3. Do I need to keep the jenkins_feed.pl and feed_bts.ini in same directory to run the script? 4. from which path is the perl script executing?
Thank you very much :-) @ chicks
Can you help me with the perl script if Ok for you as I am not able to put the things in proper way. It would be great :-)
Please edit the initial question to include the source code from the script and whatever specific questions you have about it.
I have added the source code repo can you please help here
|
0

See below to understand line by line use of your script -

#!/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

1 Comment

Thanks @ vipin kumar two questions here is Link_A a kind of file ? what is feed_bts.ini ? is that a file what kind of file is it , with regards to the content?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.