Script runs in Windows but fails in Jenkins - bash

I have a bash script :
C:/Jenkins/workspace/xmlstarlet-1.6.1-win32/xmlstarlet-1.6.1/xml.exe ed -L -s "/Package/types[name='$TYPENAME']" -t elem -n members -v "$ENTITY" $SCRIPTFILE
C:/Jenkins/workspace/xmlstarlet-1.6.1-win32/xmlstarlet-1.6.1/xml.exe ed -L -s "/Package" -t elem -n types -v "" $SCRIPTFILE
which inserts node for a particular type in an xml, this runs fine in local, but when trying to run via any script it fails:
Ant script:
<exec executable="C:\Program Files\Git\bin\bash.exe" osfamily="windows">
<arg value="generate_package.sh" />
<arg value="C:/Jenkins/workspace/TrailheadBranchDemo/final.txt" />
<arg value="package" />
<arg value="C:/Jenkins/workspace/deploy/src" />
</exec>
Error message :
Invalid expression: C:/Program Files/Git/Package
It is not able to pick the /Package or /Package/types[not(*)] expression.

The issue is :
on windows the bash script works like this:
$ C:/Jenkins/workspace/xmlstarlet/xmlstarlet/xml.exe ed -L -i "Package" -t attr -n xmlns -v "http://soap.sforce.com/2006/04/metadata" C:/Jenkins/workspace/deploy/src/package.xml
instead of this :
$ C:/Jenkins/workspace/xmlstarlet/xmlstarlet/xml.exe ed -L -i '/Package' -t attr -n xmlns -v "http://soap.sforce.com/2006/04/metadata" C:/Jenkins/workspace/deploy/src/package.xml
the /Package is not recognized well in windows.

Related

Apache JMeter error when running a test from CMD

I'm trying to run a JMeter test script from the CMD prompt but I keep getting this error:
An error occurred: The file C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin\templates\LoginPage.jmx -l C:\Users\xxxxx\Documents\Results\Jmeter.csv -e -o C:\Users\xxxxx\Documents\Results\report.csv doesn't exist or can't be opened
This is the command I'm running:
C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin>jmeter -n -t "C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin\templates\LoginPage.jmx -l "C:\Users\xxxxx\Documents\Results\Jmeter.csv" -e -o "C:\Users\xxxxx\Documents\Results\report.csv"
I'm just testing it out so ignore the folder location etc
Any ideas?
Here is the problem:
C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin>jmeter
^ ka-boom
you need to change the > to \ and the command should start working as expected
Full commmand just in case:
C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin\jmeter -n -t "C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin\templates\LoginPage.jmx" -l "C:\Users\xxxxx\Documents\Results\Jmeter.csv" -e -o "C:\Users\xxxxx\Documents\Results\report.csv"
More information:
How Do I Run JMeter in Non-GUI Mode?
Generating Reports
This is the command you provided:
C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin>jmeter -n -t "C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin\templates\LoginPage.jmx -l "C:\Users\xxxxx\Documents\Results\Jmeter.csv" -e -o "C:\Users\xxxxx\Documents\Results\report.csv"
If we break it up into multiple lines and strip off the prompt, for clarity, we get:
jmeter ^
-n ^
-t "C:\Users\xxxxx\Downloads\apache-jmeter-5.5\apache-jmeter-5.5\bin\templates\LoginPage.jmx ^
-l "C:\Users\xxxxx\Documents\Results\Jmeter.csv" ^
-e ^
-o "C:\Users\xxxxx\Documents\Results\report.csv"
You will notice that the filename passed after -t is missing a quote at the end.

Have kafkacat produce both name of a file and its contents

I want kafkacat to write both the name of a file and its contents in a single bash command, if possible. The following apparently does not work. What am I missing?
kafkacat -T -P -b ... -t ... <(echo $file) $file

Shell script works from command line but not from cron

I am using https://stackoverflow.com/a/42955871/308851 and it works from command line but not from cron. I even tried running the script with env -i but it stubbornly works.
#!/bin/bash
filename=$(date '+%Y-%m-%d').gz
docker exec -t elastic_db.1.$(docker service ps -f 'name=elastic_db.1' elastic_db -q --no-trunc | head -n1) mysqldump example |gzip -9 > /container/$filename
docker exec -t elastic_drupal.1.$(docker service ps -f 'name=elastic_drupal.1' elastic_drupal -q --no-trunc |head -n1) rclone --config /etc/rclone.conf move /app/$filename example:example/dump/
This compresses a 0 byte file when ran from cron but works just fine otherwise. What am I doing wrong?
Gordon Davisson's comment is correct: changing docker to /usr/bin/docker worked.

Unable to fetch line from crontab -l via pssh command

I have a file /tmp/hostlist containing hosts 1000+ . I am trying to fetch line which has particular word from crontab -l on 1000+ hosts via pssh command to expedite the task, but unable to fetch the line
I am trying below command. The reason for using echo \$(echo ) is to display the output in same line when triggering more than one OS command
pssh -h /tmp/hostlist -i "echo \$(echo ), \$(crontab -l|grep root)"
The above command works fine when i replaced "crontab -l|grep root" with any OS Command , Having an issue with crontab -l -> It doesn't display the expected output.
Just to add-
The above command works when using only one Command as below.
pssh -h /tmp/hostlist -i 'crontab -l|grep -i root' --> Works fine
Is there any possibility to use more than one command and display output in one line with crontab -l command like below.
pssh -h /tmp/hostlist -i "echo \$(echo ), \$(crontab -l|grep root), \$(uptime)" --> doesn't work or doesn't give expected output of crontab -l|grep root
and when using below without crontab command works fine.
pssh -h /tmp/hostlist -i "echo \$(echo ), \$(uname -a), \$(uptime)" --> Works fine

Target directory with space in PuTTY pscp via NAnt

This target is OK (D:\Temp\sgr.tar.gz):
<target name="myTarget" description="Download application delivery file">
<exec program="pscp.exe">
<arg line="-batch -v -l ${ftp.user} -pw ${ftp.password} ${ftp.host}:${remote.dir}/${remote.file} D:\Temp\sgr.tar.gz"/>
</exec>
</target>
This target (with a space in target directory (D:\tmp 2\sgr.tar.gz)) is KO:
<target name="myTarget" description="Download application delivery file">
<exec program="pscp.exe">
<arg line="-batch -v -l ${ftp.user} -pw ${ftp.password} ${ftp.host}:${remote.dir}/${remote.file} D:\Temp\tmp 2.tar.gz"/>
</exec>
</target>
I have this error:
[exec] More than one remote source not supported
I try with but is KO also.
Wrap the path to double-quotes (&quot):
<arg line="-batch -v -l ${ftp.user} -pw ${ftp.password} ${ftp.host}:${remote.dir}/${remote.file} "D:\Temp\tmp 2.tar.gz""/>
See How to escape double quotes in XML attributes values?

Resources