wsadmin jython script call method in script - websphere

Is there a way to call specific functions in a jython script through the wsadmin program?
# BusAndBusMemeber.py
def devCreateBus:
AdminTask.createSIBus('[-bus intjmsbus -description [SIBus intjmsbus] -busSecurity false]')
AdminTask.addSIBusMember('[-bus intjmsbus -node ctgNode01 -server MXServer]')
AdminConfig.save()
def devDeleteBus:
AdminTask.deleteSIBus('[-bus intjmsbus]')
AdminConfig.save()
from server cmd prompt:
C:\IBM\WebSphere....\bin> wsadmin -conntype SOAP -user myUsername -password
myPassword -lang jython -f BusAndBusMember.py devCreateBus
Or
C:\IBM\WebSphere....\bin> wsadmin -conntype SOAP -user myUsername -password
myPassword -lang jython -f BusAndBusMember.py [devCreateBus]
so far the only way I've been able to execute the jython script is by simply scripting out the AdminTasks.
thanks.

It is a bit of a hack but you can append this to your script:
globals()[sys.argv[0]]()
An alternative is to keep your functions in this file and write a second python script that does the logic of which functions to call:
import sys
execfile("BusAndBusMemeber.py")
if sys.argv[0] == "devCreateBus":
devCreateBus();
else:
print("Unknown arg %s" % sys.argv[0])

You could also combine the -profile and -c options like:
.wsadmin.sh -profile "functions.py" -c "print devCreateBus()"
It will still run through the whole -profile script so you probably just want functions in there not a "main".

Related

h2 SCRIPT command doesn't export everything

I am trying to export a h2 database using the script command. After the export, I am only getting one line in the resulting test.sql - CREATE USER IF NOT EXISTS SA SALT '05767239a3f290a0'....
I tried using the SQL command SCRIPT and also the command line, as follows. The result is the same in both cases:
SCRIPT TO "myfolder/test.sql"
java -cp h2-1.4.197.jar org.h2.tools.Script -url "jdbc:h2:~/test;AUTO_SERVER=TRUE;MV_STORE=FALSE" -user sa -password gw -script test.sql
What could I be doing wrong?
Also, does the script command export the information_schema?

how to call Remote bat script which in turn call cmd using PSExec

I am struggling please help on this.
I had two windows server A and B need to execute the cmd file in Remote Server B from A
used PSExec but nothing works.
PsExec.exe -accepteula \\machinename -u Domain\user -p password -s cmd /c C:\tmp\import.bat
shows:-
Starting cmd on machine...ice on machine.
The system cannot find the path specified.
cmd exited on machine with error code 3.
If I change like this
PsExec.exe -accepteula \\machinename -u Domain\user -p password -s -d cmd /c C:\tmp\import.bat
shows:_
started with process id but nothing execute any thing I missed.
stop.bat which in turn calls the cmd file like below
call C:\Rad\PS1\import.cmd -f C:\Rad\PS1\a.rddp
If You have at least PowerShell version 2.0 in both servers,
Open PowerShell and try
Invoke-Command -ComputerName <Computer Name> -ScriptBlock {start-process C:\tmp\import.bat} -credential (Get-Credential)
#Give domain\username and Password when Promted
More about_Remote

No password for psExec works, but empty string to password flag does not

I'm using a program called psExec to remotely connect to a machine and start an interactive program.
The machine I'm connecting to, does not have a password.
So if I run this:
psExec \\Computer_Name -u User -i -d calc.exe
It prompts me for a password:
Password:
I just hit enter(since the computer doesn't have a password), and it works.
I don't want to have to hit enter every time, because I am writing a script.
So I tried this:
psExec \\Computer_Name -u User -p -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p"" -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p'' -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p "" -i -d calc.exe
and this:
psExec \\Computer_Name -u User -p '' -i -d calc.exe
but no matter what, specifying the p flag results in a "Wrong Username or Password error."
How can I tell my script to either press enter automatically, or automate psExec to connect automatically without a password?
I'm in PowerShell if that is relevant.
PSEXEC is a program that is offered as a suite of tools from Microsoft. PSEXEC Link
but for security reasons this can cause some issues, you can add a second account to the machine and give it a simple password and run the script against that account, that would be the easiest way, other wise you can most likely accomplish the same task in powershell not using PSEXEC, what is it that you are trying to do and we can try help get something written.
UPDATE:
param (
[Parameter(Mandatory = $true)]
$Password
)
psExec \\OAIJCTDU8024272 -u User -p $Password -i -d calc.exe
It seems to work if you put a ~ for the password in powershell.
./psexec -i -u domain\gmsa$ -p ~ notepad.exe
My use case was getting it to skip the enter keypress when using psexec to run something as a group managed service account (gMSA).
Give this a shot when all else fails. It just passes a return.
Write-Host "" | psExec \\Computer_Name -u User -i -d calc.exe

Howto use psexec via powershell invoke-command on a remote computer? (invalid handle)

I have written a powershell script which creates a powershell script or a batch script depending on the remote host on which this script should be started remotely (either via powershell invoke-command or psexec).
The script creates either a powershell or a batch script, because not all hosts on which these created scripts should be run support WinRM (Windows Remote Management).
The created scripts include some psexec lines which executes a command on another remote host. The created batch script works as expected, but from the created powershell script i get the following errors from the psexec calls.
NotSpecified: (:String) [], RemoteException
+ CategoryInfo : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
+ PSComputerName : <HOSTNAME REPLACED>
PsExec v2.1 - Execute processes remotely
Copyright (C) 2001-2013 Mark Russinovich
Sysinternals - www.sysinternals.com
The handle is invalid.
Access is denied.
Connecting to 10.XXX.XXX.127...Couldn't access 10.XXX.XXX.127:
Starting PSEXESVC service on 10.XXX.XXX.127...Could not start PSEXESVC service on 10.XXX.XXX.127:
Connecting to 10.XXX.XXX.127...Starting PSEXESVC service on 10.XXX.XXX.127...
Here is a small overview of what is done:
Powershell script on deployment host creates the rollout script (ps1 or batch) depending on the destination host
Powershell script on deployment host starts the created rollout script on the destination host
Powershell will be started via Invoke-Command -ComputerName <destination host> -FilePath <path to created script> -Authentication default
Batch will be started via & psexec.exe \\<destination host> -n 60 -accepteula -c -f <path to created script>
Created rollout script on the destination host executes a psexec command to start a service on a third host (this fails only if the rollout script is powershell)
This is the psexec command which fails if executed via a remotely started powershell script.
& psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename>
The same command psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename> executed via a remotely started batch script works without problems.
Update #1
Also if i connect to the destination host with rdp and start a powershell shell and paste the command it works without issues. The problem only occurs if started remotely.
I already tried the following variants of starting psexec, all without luck!
& psexec.exe \\<destination host> -n 60 -accepteula -s -u <user> -p <password> net stop <servicename>
Start-Process cmd.exe -Credential "<domain>\<user>" -WorkingDirectory $env:systemdrive -ArgumentList "/C psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename>"
Start-Process powershell.exe -WorkingDirectory $env:systemdrive -Verb Runas -ArgumentList "cmd.exe /C psexec.exe \\<destination host> -n 60 -accepteula -u <user> -p <password> net stop <servicename>"
can you try to replace your psexec command, and use cmd.exe like thisn also add -s to psexec so it will run as system user. My testing command :
icm -cn computer1 -ScriptBlock{ cmd.exe "/c psexec -s -u <login> -p <password> /accepteula /n 10 \\computer2 net start audiosrv"}
You are running into the Second Hop problem:
http://blogs.technet.com/b/heyscriptingguy/archive/2012/11/14/enable-powershell-quot-second-hop-quot-functionality-with-credssp.aspx
The answer is to enable the appropriate relationship between the two computers involved (see previous link or just search google for 'powershell' and 'second hop') and to add to Invoke-Command:
-Authentication Credssp -Credential
What worked for me was:
Start-Process -FilePath .\PsExec.exe -ArgumentList "/acceptEula /s \$Computer program.exe /arg"

Getting error with: pbsu & pbrun commands via Plink (command not found)

I'm doing automation for run commands via Plink. Below is required step to run command in my environment:
Login to unix machine:
host: myhost
user/pass: myuser/Mypass
Use command: pbsu - uatwrk1
(Or command: pbrun –u uatwrk1 pbksh)
->it will redirect to other machine and some commands to be executed there
Run some commands
******Issue*******
(I) When I execute the Plink command line below in CMD, I'll get error:
The content of script.txt:
pwd
pbsu - uatwrk1
pwd
runcommand.ksh
plink -ssh myuser#myhost -pw Mypass -m "C:\script.txt" > "C:\log.txt"
Error: "sh: pbrun: command not found"
(II) But it works with command by command:
cmd>plink -ssh myuser#myhost -pw Mypass
$pwd
$pbsu - uatwrk1
$pwd
$runcommand.ksh
Please help to to figure out why the command pbrun failed on (I) while it worked on (II) ?
I need (I) works as it provides the capture log to check further in my automated application (using VBA).
Thanks a ton for any help!
It is possible if in the interactive session (II) you have another environment than in the batch session (I). You must check what PATH and current directory you have in the both cases.

Resources