Passing variables to sshexec command resource file in ANT - unix

I have created a large script to be passed to an sshexec commandResource in ant as follows.
<sshexec host="${host.server}"
username="${username}"
password="${oracle.password}"
commandResource="path-to-file/script.txt"
/>
This is working as intended.
There are several lines that will get executed on the server in that script. The contents of the script.txt file is as follows :
/script/compile_objects.sh /path-to-code/ login password
/script/compile_code.sh /path-to-code/ login password
However, I would prefer to not store the login and password as clear text in the script.txt file. Is it possible to pass parameters to each line of the command resource. I'm aware that each line in the command resource file gets executed in its own shell.
I tried string replacement from a property in the Ant script, but it failed with a bad substitution error like so. Is there another way to do this?
<property name="oracle.password" value="thepassword"/>
and then in the script file, alter to:
/script/compile_objects.sh /path-to-code/ login ${oracle.password}
/script/compile_code.sh /path-to-code/ login ${oracle.password}
This type of replacement works when using the command feature, but seems to fail when using commandResource.
Edit :
I am using Apache Ant 1.9.4
and jsch-0.1.54.jar

Related

SQL Server Management Studio will not redirect output from command line

I am using SQL Server Agent to run a few scripts regularly of type CmdExec with the following format:
"Absolute path to RScript.exe" "Absolute path to script.R" > "Absolute path to log folder\logfilename.txt"
This line will work when used manually in the command prompt but won't create a log file when executed through SSMS. Anyone else have trouble dealing with SSMS or is there a problem with my line?
What also works (in the sense that a file is created) in SSMS is type nul > "Absolute path to log folder\logfilename.txt" so there is no problem with the file path or write permissions.
Not sure if this piping is possible for "normal" commands, but under Step Properties -> Advanced, you can choose to save output to file

Module socket not found lua

I am trying to use lua to access redis values from nginx. When i execute lua files on command line there everything is ok i am able to read and write values to redis. But i when try to execute the same files from nginx by accessing a location in which access_by_lua directive is written the following error logged in error log file
no field package.preload['socket']
no file '/home/sivag/redis/redis-lua/src/socket.lua'
no file 'src/socket.lua'
no file '/home/sivag/lua/socket.lua'
no file '/opt/openresty/lualib/socket.so'
no file './socket.so'
no file '/usr/local/lib/lua/5.1/socket.so'
no file '/opt/openresty/luajit/lib/lua/5.1/socket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
What is the reason for this and how can i resolve this?
In my case I just needed to install the lua-socket package, as the socket library is not built into the default Lua installation like it is in some other languages.
You get this error because your code executes the command require("socket")
This command will search for a file with that name in several directories. If successful the content will be executed as Lua code. If it is not successful you'll end up with your error message.
In order to fix this you have to add the path containing the file either to the system variable LUA_PATH or you have to add it to the global table package.path befor you require the file.
Lua will replace ? with the name you give to require()
For example
package.path = package.path .. ";" .. thisPathContainsTheLuaFile .. "?.lua"
Please read:
http://www.lua.org/manual/5.3/manual.html#pdf-require
https://www.lua.org/pil/8.1.html

MSDeploy Parameter

I am trying to pass application pool password as a command line argument to msdeploy.exe. Also, I am passing setParameter file as another command line agrument. The overall command line looks like this
msdeploy.exe -verb:sync -source:package=D:\package.zip,encryptPassword="password" dest:auto,computername=mycompuetrname -setParam:name="AppPoolPassword",value="mypassword" -setParamFile="D:\Test.setParameters.xml"
Other things to be noted, Test.setParameters.xml file does NOT have AppPoolPassword param, because I want to pass that as command line as mentioned above.
When I execute the above command, I get an error which says "ApplicationPoolPassword cannot be null". If I do not specify the parameters.xml file but just specify AppPoolIdentity and AppPoolPassword on the command line the command is successful and creates the necessary web site structure.
My question is does setParamFile overrides the -setParam command line paramters? I did google search but did not find anything which confirms that. Anyone who has experienced this, please help.
Thanks
Regarding setParamFile overriding setParam, you've got it backwards. The setParam parameter takes precedence over the setParamFile.
Regarding the error, it looks like your parameter names are off. The error references parameter name "ApplicationPoolPassword". Your command is using the parameter name "AppPoolPassword". Try changing the command to use the name "ApplicationPoolPassword".

Installing an MSP using Powershell works on the local machine, fails remotely. Why?

I need some Powershell advice.
I need to install an application's MSP update file on multiple Win08r2 servers. If I run these commands locally, within the target machine's PS window, it does exactly what I want it to:
$command = 'msiexec.exe /p "c:\test\My Application Update 01.msp" REBOOTPROMPT=S /qb!'
invoke-wmimethod -path win32_process -name create -argumentlist $command
The file being executed is located on the target machine
If I remotely connect to the machine, and execute the two commands, it opens two x64 msiexec.exe process, and one msiexec.exe *32 process, and just sits there.
If I restart the server, it doesn't show that the update was installed, so I don't think it's a timing thing.
I've tried creating and remotely executing a PS1 file with the two lines, but that seems to do the same thing.
If anyone has advice on getting my MSP update installed remotely, I'd be all ears.
I think I've included all the information I have, but if something is missing, please ask questions, and I'll fill in any blanks.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
My process for this is:
Read a CSV for server name and Administrator password
Create a credential with the password
Create a new session using the machine name and credential
Create a temporary folder to hold my update MSP file
Call a PS1 file that downloads the update file to the target server
>>> Creates a new System.Net.WebClient object
>>> Uses that web client object to download from the source to the location on the target server
Call another PS1 file that applies the patch that was just downloaded –>> This is where I’m having issues.
>>> Set the variable shown above
>>> Execute the file specified in the variable
Close the session to the target server
Move to the next server in the CSV…
If I open a PS window and manually set the variable, then execute it (as shown above in the two lines of code), it works fine. If I create a PS1 file on the target server, containing the same two lines of code, then right click > ‘Run With PowerShell’ it works as expected / desired. If I remotely execute my code in PowerGUI, it returns a block of text that looks like this, then just sits there. RDP’d into the server, the installer never launches. My understanding of the “Return Value” value is that “0″ means the command was successful.
PSComputerName : xx.xx.xx.xx
RunspaceId : bf6f4a39-2338-4996-b75b-bjf5ef01ecaa
PSShowComputerName : True
__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 4808
ReturnValue : 0
I even added a line of code between the variable and the execution that creates a text file on the desktop, just to verify I was getting into my ‘executeFile’ file, and that text file does get created. It seems that it’s just not remotely executing my MSP.
Thank you in advance for your assistance!
Catt11.
Here's the strategy I used to embed an msp into a powershell script. It works perfectly for me.
$file = "z:\software\AcrobatUpdate.msp"
$silentArgs = "/passive"
$additionalInstallArgs = ""
Write-Debug "Running msiexec.exe /update $file $silentArgs"
$msiArgs = "/update `"$file`""
$msiArgs = "$msiArgs $silentArgs $additionalInstallArgs"
Start-Process -FilePath msiexec -ArgumentList $msiArgs -Wait
You probably don't need to use the variables if you don't want to, you could hardcode the values. I have this set up as a function to which I pass those arguments, but if this is more of a one-shot deal, it might be easier to hard-code the values.
Hope that helps!
using Start-Process for MSP package is not a good practice because some update package lockdown powershell libs and so you must use WMI call

Respond to shell prompts from Ant SSH task (SSHEXEC)

I'm using the SSHEXEC ant task to run an SSH script against a remote linux box.
This has worked fine until I try and call a ksh script which prompts the user for input. The script changes the current user (like su). It prompts the user for a change_request_id, and a change_request_reason. So using this command normally in a shell would look like this:
change_user deploy_user
Please enter the changes request number for doing this: 1234
Please enter the changes request reason: Because I can
<deploy_user>
But when I run these commands from SSHEXEC, it gets to the first prompt "Please enter the changes request number for doing this:" and stops. Even though I'm piping a response to this prompt via SSHEXEC, it still gets stuck here.
Unfortunately we do not have access to change or copy the change_user shell script.
I was wondering if there was some way I could use SSHEXEC which would send down prompt answers with the command.
Any help would be appreciated.
Are you able to put another script on the same server as the change user script that accepts command line parameters and then calls the change request script itself? E.g. in ksh:
#!/usr/bin/ksh
#
# $1 is change request number
# $2 is change request reason
#
/path/to/change_request_cmd <<PARAMS
$1
$2
PARAMS
It may be easier to have SSHEXEC call this script instead.

Resources