Target directory with space in PuTTY pscp via NAnt - putty

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?

Related

Script runs in Windows but fails in Jenkins

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.

Is there any command line code which can help me verify passwords for files within zip files?

I have about 200 zip files and I need to verify the password for each of the zip files. Is there any command line code which can help me verify passwords for files within these zip files?
pass="testpassword"
for arch in *.zip; do
unzip -P $pass -qq -t "$arch" && echo "Pass $pass for $arch"
done

how to write multiple exec arguments in ant

I want to write an ant script that will
start up a new terminal
Change user
and run the Appium session
This is what i have so far but it doesn't do anything
<exec executable="/bin/bash" os="${os.unix}" spawn="true">
<arg value="-c" />
<arg value="gnome-terminal su appium" />
<arg value="appium &" />
</exec>
And what is the value of the property ${os.unix}? If you're going to use the os parameter, you usually give it a string constant and not a property value.
<exec executable="/bin/bash" os="unix" spawn="true">
<arg value="-c" />
<arg value="gnome-terminal su appium" />
<arg value="appium &" />
</exec>
This way, you could have an <exec> task for all Unix style operating systems, and another <exec> task for all the other ones (Windows).
Also understand the difference between <arg value="..."/> and <arg line="..."/>. I don't know the exact command structure for gnome-terminal, but when you pass something as a value, you're passing it as a single parameter -- even if it has spaces in it. For example:
<exec executable="foo">
<arg value="-f foo -b bar"/>
</exec>
Will execute as if I typed this in the command line:
$ foo "-f foo -b bar" # This is one command with one parameter. Note the quotation marks!
If I do this:
<exec executable="foo">
<arg line="-f foo -b bar"/>
</exec>
Will execute as if I typed this in the command line:
$ foo -f foo -b bar # This is one command with four parameters
This is equivalent to the above Ant task:
<exec executable="foo">
<arg value="-f"/>
<arg value="foo"/>
<arg value="-b"/>
<arg value="bar"/>
</exec>
Currently, you're attempting to execute:
$ /bin/bash -c "gnome-terminal su appium" "appium &"
If this is what you want, fine. By the way, you could skip the whole /bin/bash stuff on Unix:
<exec executable="gnome-terminal" os="unix" spawn="true">
<arg value="su appium"/>
<arg value="appium &"/>
</exec>
Try this:
<exec executable="/bin/bash" spawn="true" >
<arg value="-c" />
<arg value="x-terminal-emulator -e 'sudo -u appium appium'" />
</exec>
os="${os.unix}" seems incorrect, I've removed it completely.
-c and bash command needs to be in separate arg element.
su will start new shell. Use sudo with argument instead.
command passed to gnome-terminal needs to be quoted.
x-terminal-emulator should be more portable than gnome-terminal.
Actually, using bash doesn't seem to be necessary at all. Try:
<exec executable="x-terminal-emulator" spawn="true" >
<arg value="-e" />
<arg value="sudo -u appium appium" />
</exec>

Writing gpg decrypted file to a specified outfile

I attempted to decrypt an encrypted gpg file using:
gpg -d <encrypted file> --output <outfile>
and just get a message:
usage: gpg [options] --decrypt [filename]
In contrast, if I use
gpg -d <encrypted file>
the file is decrypted, but it's written to a default file and displayed to the terminal screen. The former isn't a big issue, but the latter (display in terminal screen while decrypting) is a real nuisance. What, if anything, can be done about it?
Try gpg --output <outfile> -d <encrypted file>
The "-d" is unnecessary, this is fine:
gpg -o plaintext.txt ciphertext.asc
As for printing the decypted data to stdout, that usually only happens when the sender uses the old "for-your-eyes-only" flag. To determine exactly what is happening there, though, I'd need more detail on the version of GPG in use and possibly some information on the ciphertext.

GnuPG Shell Script - Refuses to read password

The script below used to work on Mac OS X, but, since moving it to Ubuntu, it doesn't seem to read from the password file at all. Even when I run it from the command line, no matter what I do, I get a popup prompt asking me for the password. As this will run via cron, I don't want this to happen... I want it to read the password from the file with no prompt. To note, I did try using passphrase-fd and passphrase-file, neither of which worked...
#!/bin/sh
p=$(<pass.txt)
set -- $p
pass_phrase=$1
destination="/var/www/decrypted"
cd /var/sl_bin/
for FILE in *.pgp;
do
FILENAME=${FILE%.pgp}
gpg --passphrase "$pass_phrase" --output "$destination/$FILENAME" --decrypt "$FILE"
rm -f $FILE
done
This works:
gpg --no-use-agent --batch --passphrase-file pass.txt --output kkkk.tar.bz2 --decrypt kkk-data.tar.bz2.gpg
The --passphrase-file option seems to be broken / not honored. I had to use --passphrase-fd 0 instead, like so:
cat .password | gpg --passphrase-fd 0 --output foo --decrypt foo.gpg
Use option --no-use-agent. It won't prompt you using option --passphrase.
If you don't want to supply the file via standard input (eg, because you're plugging this into another command like git, which wants to supply the content to sign via standard input), then you can use another file descriptor:
gpg --passphrase-fd 3 <your command here> 3< pass.txt
Your problem is probably that $passphrase is null. On Ubuntu sh is symlinked to dash which doesn't understand $(<file_name) in the same way that Bash does (but doesn't issue an error either).
You can change your shebang to:
#!/bin/bash
or use $(cat pass.txt)
Also, why not combine the second, third and fourth lines?: pass_phrase=$(<pass.txt) (or pass_phrase=($(<pass.txt)) if you're trying to strip off all but the first "word" in the file).
Your previous question
use
#!/bin/bash
or
#!/usr/bin/env bash
as your first line instead of #!/bin/sh
As for your pass phrase problem, you should probably try to use some automatic mechanism. check the gpg documentation for information. I don't use gpg, but you can check out gpg-agent.
Two solutions (the first one solved my problem ;-))
http://www.roguedaemon.net/rephrase/
gpg uses --passphrase-fd not --passphrase
echo yourpw|gpg --passphrase-fd 0 --output out.txt -d file.txt
You're getting password prompt because you have DISPLAY variable set (if you click cancel the script will continue decrypting files). DISPLAY shouldn't be set in the cron environment, so you can probably ignore it, but to be sure or be able to test the script from command prompt add
unset DISPLAY
to the beginning of the script or run it before executing.
Also to be able to use $(<file) syntax you need to change
#!/bin/sh
to
#!/bin/bash
You should avoid using --passphrase option which could lead to revealing your password on multi-user system. You can use --passphrase-file instead. Here's how I would change your script:
#!/bin/sh
PASSFILE=$(pwd)/pass.txt
destination="/var/www/decrypted"
cd /var/sl_bin/
for FILE in *.pgp;
do
FILENAME=${FILE%.pgp}
gpg --passphrase-file $PASSFILE --output "$destination/$FILENAME" --decrypt "$FILE"
rm -f $FILE
done
To save location of the password file before changing current directory, I saved it in PASSFILE variable.
add --archive to read password from --passphrase-file
You must to use:
gpg --batch --passphrase-fd 1 --passphrase-file your_password_file -c your_file_to_encript.txt
Use below script
#! /bin/sh
gpg --pinentry-mode loopback --passphrase='PASSWORD' --output /output/outputFileName /input/inputFileName

Resources