I am trying to run a DB2 command (Import) from a windows batch script.
My approach is..
Invoke DB2 command prompt: DB2CMD.exe DB2SETCP.BAT DB2.EXE
Connecting to the database: connect to DBNAME USER USERNAME USING PWD
Executing DB2 command: IMPORT FROM ...
quit
The batch script looks like this..
DB2CMD.exe DB2.EXE "connect to dbname USER username USING pwd" "IMPORT FROM D:\File.txt .... INSERT_UPDATE INTO tablename"
quit
It is working till the second step and the bat script is exiting without running the third step.
Can anyone guide me on this.. Thanks!
To run Db2 commands in a CMD/BAT file on Microsoft Windows, you need to have a Db2 client installed, and you can begin all of the BAT or CMD files
with the pattern below. This lets your script open the DB2CMD.EXE if that is not already opened (so you don't need to do it manually). You also need to have the database catalogued so that you can access the database from the Windows CMD.EXE or DB2CMD.EXE command line. Always verify your commands at the command-line before putting them into a script.
When you get any error, you must specify the exact error when asking for help, either by using copy/paste from the db2cmd window or by attaching a screenshot.
Your second step cannot just exit without first showing some error message, although you may need to ensure that the window does not close before you can see that message. There are many reasons for IMPORT to fail, but you have given no information about which reason Db2 gave. If you edit your question to specify the missing error detail, you will get more help on here.
If you run the script on the same hostname where the database is running then you don't need to specify a userid/password and then it connects as the currently logged on User.
If you need to connect to the database with a specific userid (different from the user logged in to Windows) or if you need to connect to a remote database then you must specify a password to the connect command. You can ask the user to enter a password, for interactive scripts. If you need to have an unattended script you should avoid hardcoding the password in plain text in the script, or use runas.
The example below shows both a connect to a local database, and a remote database (choose only one of the methods).
#if ""%DB2CLP%""=="""" db2cmd /c /i /w ""%0"" %* && goto :EOF
#rem for connecting to a local database as current logged-in Windows account (no password required)
db2 -v connect to dbname
#if errorlevel 1 ( #echo ""FAILED to connect"" && #goto :EOF )
#rem for connecting to a remote database, or connecting with a different account
db2 -v connect to dbname user YOURUSER using THEPASSWORD
#if errorlevel 1 ( #echo ""FAILED to connect"" && #pause ... && #goto :EOF )
db2 -v "IMPORT FROM TO ... "
#if errorlevel 2 ( #echo "FAILED to export..." && #pause ... && #goto :EOF )
db2 -v connect reset
Related
I'm trying to load flat file into server through FTP using batch files. I'm aware of the scripts and I'm able to transfer the file to server. Currently I'm following this below method.
#echo off
title File Transfer
color 3F
cd "C:\Users\username\Desktop\Access\"
echo -
echo - Transferring File to Server. Please be patient...
echo -
echo - Closing this window will Terminate the entire process
ftp -n -s:"C:\Users\username\Desktop\Access\ftp.txt" server_name >"C:\Users\username\Desktop\Access\ftp.log"
Script File Code: (ftp.txt)
User Userid password
mkdir App
put "C:\Users\username\Desktop\Access\File.txt" "App/File.txt"
quit
My requirement is that I should not display username and password on the script file. These credential information dynamically coming from the variables and I'm generating this batch file and script file dynamically.
Kindly any experts suggest me solution which makes more sense to accomplish this requirement. Thanks in advance.
You generally cannot encrypt anything while still allowing it to be decrypted automatically.
See for example BASH: allow users to FTP files to my server without revealing FTP login credentials to them
All you can typically do is to obfuscate the credentials. But the Windows ftp.exe does not allow even that.
With ftp.exe, you can use input redirection to somewhat reduce the risk:
(
echo user %USERNAME% %PASSWORD%
echo mkdir ...
echo put ...
echo quit
) | ftp.exe -n example.com
I have a requirement, want to check is informatica services running or not if not running should send a mail.
"How to Ping informatica Integration Service in windows server using batch script & send a email if it is NOT available or NOT responding.
Any script for this requirement pls share.
Thanks...
I'm guessing you use the code pmcmd pingservice -sv Home_practice_PCI_service -d domain_wininfa in your cmde to see if it is running or not. Try to put this in a batch file and see what it echos:
#echo off
pmcmd pingservice -sv Home_practice_PCI_service -d domain_wininfa
echo %errorlevel%
pause
If you notice that the errorlevel changes if the service is not online, you can try using this script:
#echo off
pmcmd pingservice -sv Home_practice_PCI_service -d domain_wininfa
if "%errorlevel%"=="1" start "" "mailto:test#email.com?subject=Service%%20crashedg&body=Informatica%%20Integration%%20Service%%20stopped%%20responding "
Replace the 1 with the number the first script shows you when the service is not responding, and change the email to your desired email address. Note that you will still have to send the email yourself, this just opens that email in your default mail service
I have written a batch file which starts OpenVPN. If the client is found, I check the connectivity by running PING. If the server is not found, then this means that although OpenVPN is running, the connection has not been established. At this point I want to restart OpenVPN. Because I am not using the admin account for this script, I always get the error "permission denied" when using TASKKILL /F. Is there anyway around this?
There are two methods of running a command with administrator privileges.
Solution 1:
Right-Click the batch-file and click run as admin.
Solution 2:
Use the runas command to run a command or batch file with administrative permissions. This way the process is still automate but you will still need to type in the password for administrator.
Example:
C:\> runas /user:administrator "taskkill /f /im explorer.exe"
Enter the password for administrator:
Type runas /? for more info.
if you are already the administrator, you can create a shortcut to your batch file and when you right click the shortcut -> properties -> advanced -> check the checkbox "run as administrator"
and voila!
everytime you run the batch script via this shortcut file, it will run as administrator and will kill without any discrimination, happily ever after
I have a Server 2008 R2 Standard. I need to execute a batch-file using psexec from my PC Win7. The only time this worked is when i disabled the UAC on my server. Deactivating the UAC is out of the question, I'm looking for a solution with UAC enabled.
Error message:
Could not start PSEXESVC service on remotehost:
Access denied.
PS: In my command line of psexec I'm using the administrator user of my server to execute the batch-file. The UAC level is 3 on my server.
Best regards,
Tasso
It took me hours to find a working way to PsExec between two Windows 7 computers with a non-Admin user starting PsExec.
Disabling UAC...
EnableLUA=0
ConsentPromptBehaviorAdmin=0
LocalAccountTokenFilterPolicy=1
...did not work, turning off the firewall did not work.
Here I found the working way - thanks JelmerS (PSexec is not connecting to machine using supplied username and password).
*This is because psexec still tries to access the ADMIN$ share with your local credentials, before executing your command as another user. According to this thread, you can cache credentials before executing psexec:
cmdkey.exe /add:MACHINE_NAME_HERE /user:MACHINE_NAME_HERE\Administrator /pass:PASSWORD_HERE
psexec.exe \\MACHINE_NAME_HERE -i notepad
cmdkey.exe /delete:MACHINE_NAME_HERE*
Best regards, Peter
It seems that running PsExec from a Win7/Win2K8 machine against a Win7/Win2K8 target, regardless of the "-u" and "-p" params on the PsExec command-line,those params are ignored and PsExec is being executed remotely with whatever user credentials we happen to be logged in locally with.
Even though you stating which user account to execute the command on the remote system it executes the psexec command as the user that opened the command window.
When opening the Command Prompt, please right click it and select 'run as Administrator'. Meanwhile, make sure the user has administrator privileges on target PC.
The only solution i see to offer is to use the "Runas" (with the account you will need on the remote system) command to execute PsExec and forget the -u -p params.
In command prompt, you can try as,
echo "password" > pwd
runas /env /netonly /user:domain\Administrator "psexec.exe your_local_program.bat" < pwd
del pwd
Or just:
echo password | runas /env /netonly /user:domain\Administrator "psexec.exe your_local_program.bat"
Moreover....
Don't forget to check your Anti-virus which frequently blocks several of the PStools.
I am Help Desk for a company and we have some computers on our VPN. We sometimes have to use Windows Remote Desktop to login to these computers. (mostly Windows XP but some Windows 7)
When we remote into a Windows the computer/session is locked
I would like to be able to make a popup appear on their computer saying they can log back in.
I use 2 command-line tools in order to issue remote commands: psexec & nircmd.
nircmd is useful because it has command-line options to make a pop-up but it will pop-up inside the session not on the "computer locked screen".
I have played with Local Security Policy and it will you to display a message when they first login but not while the session is locked.
It does have an option to display username while session is locked so somehow it can display certain things during a locked session.
#npocmaka Thanks
I ended up using msg.exe but because of restrictions on our company's network I used a combination of psexec and msg
msg server:IPADDRESS /v "message"
didn't work so I used
psexec \IPADDRESS -u username -p password msg /server:IPADDRESS /v "message"
but in order for it to work I had to run
psexec \IPADDRESS -u username -p password reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v AllowRemoteRPC /t REG_DWORD /d 1 /f
on the remote computer. I got the reg command from another post in StackOverflow actually!