I'm new to WIMC so probably there will be simple answer to my question.
If I will open CMD and run this command:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%Windows%'" get DisplayName,Name,PathName,State,StartMode
this will generate file with all services not in windows folder.
If I will save above command in bat file and run this will generate list all services somehow ignoring WHERE statement. Running this as Administrator not changing anything.
In a batch script you have to double pump the % signs so they'll be treated as literal percent signs. Change your command to this and it'll work:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%%Windows%%'" get DisplayName,Name,PathName,State,StartMode
Related
I would like to make a batch file that can write sql request into an .exe that is running as a cmd prompt window.
My idea was to put my sql script into an .txt file that the batch request and insert into my second prompt window.
I've found something about:
Type 'mytext.txt' | myexe.exe
But its not working.
What I want to do is a Batch that send my sql request into that .exe run as a cmd prompt, so I can automate that process.
Any idea?
Thanks
Depends heavily on the capabilities of that exe-file.
What does it poll for ? Is it written to handle pipes ?
https://technet.microsoft.com/en-us/library/bb490982.aspx gives you an overview of the command redirection operators.
Not knowing what the exe is capable of makes this question really hard to answer.
I have a scheduled task using Windows 7 to run a .exe file at a specific hour, which in-turn creates a .txt file and saves it in a folder. I am trying to write a script that will automatically send this .txt file to a FTP server without me using cmd.
I am working with this script thus far
open ftp.site.com
username
password
put c:\folder\file.txt
quit
FTP doesn't require CMD. It can run in it's own console window.
FTP /? shows
-s:filename Specifies a text file containing FTP commands; the
commands will automatically run after FTP starts.
The script file contains exactly what you would type interactivly.
Supposing your current scheduled task runs a command like:
c:\folder\someapp.exe c:\folder\file.txt
Change that to
c:\folder\script.bat
Where the c:\folder\script.bat batch file will look like:
c:\folder\someapp.exe c:\folder\file.txt
ftp.exe -s:c:\folder\ftp.txt
And the c:\folder\ftp.txt will contains your FTP script:
open ftp.site.com
username
password
put c:\folder\file.txt
quit
I want to automate the export process which I take using expdp command in Oracle.
Following is the contents of batch file I have created to open PuTTY.
#echo off
"C:\Program Files\PuTTY\plink.exe" username#Ip_Addr -pw password -m Open_Putty.txt`
Following is the contents of Open_Putty.txt to execute different commands.
echo $ORACLE_SID;
Read oraenv;
But after opening Open_Putty.bat it disappears without showing any output.
Please help me with this. I want to set oraenv and run some more commands to take the backup.
It's unlikely that plink.exe disappears without showing any output. I assume you execute the batch file from a Windows Explorer or other GUI application, so the Plink console window disappears once Plink finishes (possibly with error) and you cannot read the output (error).
Make sure you execute plink.exe from a console window (typically a cmd.exe) or add pause command to the end of the batch.
Make sure Plink can find the script file (Open_Putty.txt). As you do not specify a path to the file, it has to be located in your current working directory. Safer is to use a full path to the script file:
"C:\Program Files\PuTTY\plink.exe" username#Ip_Addr -pw password -m "C:\path\Open_Putty.txt"
The backtick symbol at the end of the command should probably not be there.
The name "Open PuTTY" is bit confusing. You are not using PuTTY at all. And even if you refer to Plink by "PuTTY", your script file (Open_Putty.txt) is not opening PuTTY nor Plink. It's executing remote commands. So you should better name it export.txt or similar.
I deploy some .bteq and .sql scripts on a TERADATA database. For doing this, I use a client on my desktop called BTEQWin version 13.10.0.03.
I get the .bteq/.sql from a version control like pvcs/svn etc and all I do once the files are in my workspace folder (from Version control tool), to just drag and drop the files from Windows browser to BTEQWin client (which I connect to a database prior to drag/drop for running those scripts).
Now, I have to automate this whole process in UNIX.
I have written a SHELL KSH/BASH script which is getting all the .bteq/.sql from a TAG/LABEL in the version control tool to a given UNIX folder. Now, all I need to do is the pass these files one by one (i'll take care of the order) to Teradata client.
My ?
- what client do I need to tell Unix admin team to install on Unix server - so that I can run something like below:
someTeraDataCommand -u username -p password -h hostname -d database -f filenametoexectue | tee output_filename.log
Where, someTeraDataCommand is the client / executable - which will let me run Teradata scripts (like I was doing using BTEQWin on my desktop - GUI session). Other parameters can be username, password, which database to connect on what server and which file to run or make that file passed to the command using "<" operator at command line.
Any idea?
- What client ?
Assuming the complete Teradata Tools and Utilities package is installed on your UNIX server (which will have the connectivity tools to talk to Teradata), you should have access to bteq from the command line. Something like this:
bteq < script_file > output_file
Your script file should contain a .LOGON statement to establish the connection:
.LOGON yourTDPID/your_account,your_pw
You might also need to use other commands to set your default database or non-default session values.
Another option would be to combine the SQL and call to BTEQ in a Korn shell script:
#!/usr/bin/ksh
##############
SHELL_NAME=`basename $0`
PRG_NAME=`basename $(SHELL_NAME} .ksh`
LOG_FILE=${PRG_NAME}.log
OUT_FILE=${PRG_NAME}.out
#
bteq <<EOBTQ > ${LOG_FILE} 2>$1
.LOGON {TDPID}/{USERID},{PWD};
--.RUN file=${LOGON}
/* Add your SQL/BTEQ commands here */
.QUIT 0;
EOBTQ
Edit
The double hyphen indicates a single line comment. Typically in a UNIX script you do not leave your password in plain text of a KSH script. The .RUN command would reference a text file in a barely sufficient secure location containing the .LOGON {TPDID}/{USERID},{PWD}; command.
The .RUN command in BTEQ allows you to reference another text file containing a series of valid BTEQ commands that you want to run in the current BTEQ script.
Easiest way is to setup the Solaris TTU, is to request root sudo, and run an interactive installation into defaults as a root. That would cure all client issues.
I'd like to have a macro in Visual Studio 2005 that calls a DOS command and redirects the output (stdout and stderr) to a file. Just calling the command and ">" redirecting it will not capture stderr, so there are two parts to this:
calling a DOS command
capturing both stderr and stdout to a file during that call
I'd then like to open this file in Visual Studio after the command completes.
I'm new to Visual Studio 2005 macro writing, and VB/VBA, so that's the kind of help that I'm looking for.
Thanks,
Mark
In DOS, > or 1> is stdout, and 2> is stderr. So, you could say
myprog.exe 1> out.txt 2> err.txt
to send them to separate files, or
myprog.exe 1>2> both.txt
to send them to both.
In VB/VBA, you could use the Shell command to call this (assuming you didn't know that already).