Windows timeout Command

As noted in my last post, I came across two commands I had no idea natively existed in Windows. The previous one is waitfor. This command is timeout. WOW. This would have been nice to have known previous for many of my batch scripts instead of hacking up for loops to simulate a wait timeout. Argh!

TIMEOUT [/T] timeout [/NOBREAK]

Description:
    This utility accepts a timeout parameter to wait for the specified
    time period (in seconds) or until any key is pressed. It also
    accepts a parameter to ignore the key press.

Parameter List:
    /T        timeout       Specifies the number of seconds to wait.
                            Valid range is -1 to 99999 seconds.

    /NOBREAK                Ignore key presses and wait specified time.

    /?                      Displays this help message.

NOTE: A timeout value of -1 means to wait indefinitely for a key press.

Examples:
    TIMEOUT /?
    TIMEOUT /T 10
    TIMEOUT /T 300 /NOBREAK
    TIMEOUT /T -1

Windows Waitfor Command

I recently discovered a command I didn’t know about (actually 2 commands). I never knew about waitfor command! Man, this would have been useful in some of my remote package pushing scripts. I guess this has been around since Server 2003 days.

WaitFor has two ways of working:

Syntax 1: to send a signal
    WAITFOR [/S system [/U user [/P [password]]]] /SI signal

Syntax 2: to wait for a signal
    WAITFOR [/T timeout] signal

Description:
    This tool sends, or waits for, a signal on a system. When /S is not
    specified, the signal will be broadcasted to all the systems in a
    domain. If /S is specified, then the signal will be sent only
    to the specified system.

Parameter List:
    /S     system         Specifies remote system to send signal to.

    /U     [domain]user  Specifies the user context under which
                          the command should execute.

    /P     [password]     Specifies the password for the given user context.

    /SI                   Sends the signal across the net to waiting machines

    /T     timeout        Number of seconds to wait for signal. Valid range
                          is 1 - 99999. Default is to wait forever for signal.

    signal                The name of the signal to wait for or to send.

    /?                    Displays this help message.

    NOTE: A system can wait for multiple unique signal names.
    The signal name cannot exceed 225 characters and cannot
    contain characters other than a-z, A-Z, 0-9 and ASCII
    characters in the range 128-255.

Examples:
    WAITFOR /?
    WAITFOR SetupReady
    WAITFOR CopyDone /T 100
    WAITFOR /SI SetupReady
    WAITFOR /S system  /U user /P password /SI CopyDone

Tip: Change DNS Server for a Network Adapter via Command Line in Windows

Just a quick tip/note on changing the DNS server(s) for a network adapter in Windows from the command line.

To do this, you need elevated privileges on a command line (or you can use ‘runas’ from a non-elevated command line and provide administrative credentials).

c:>netsh interface ip set dns "Local Area Connection" static 8.8.8.8

To set it via DHCP you can just issue:

c:>netsh interface ip set dns "Local Area Connection" dhcp

Bulk add TXT DNS Record to Zones in Windows

Had more than a handful of domains I needed to add TXT record for in Windows DNS (2003). I did it using dnscmd from 2003 Toolkit and command line.

This will enumerate the zones (I search for Primary and exclude reverse):

dnscmd /enumzones | find /I Primary | find /V Rev > zones.txt

After I have a zones.txt file, I then loop through it to add the TXT record.

for /f %x in (zones.txt) do dnscmd . /recordadd %x @ TXT v=spf1 mx -all

A Windows “whereis” Command

This one-liner (source):

I found this batch script/command on ServerFault *I think*. Very cool little one-liner trick.

@for %%e in (%PATHEXT%) do @for %%i in (%1%%e) do @if NOT "%%~$PATH:i"=="" echo %%~$PATH:i

Example usage:

C:\Users\Rich\Desktop>whereis cmd
C:\Windows\System32\cmd.exe

C:\Users\Rich\Desktop>whereis shutdown
C:\Windows\System32\shutdown.exe

C:\Users\Rich\Desktop>whereis putty

Update: July 21, 2011 So, I discovered: “where” built-in to Windows…

Description: Displays the location of files that match the search pattern. By default, the search is done along the current directory and in the paths specified by the PATH environment variable.

“where” exists in Windows Server 2003 but I also have it natively on Windows Vista and 7.  Not sure which other Windows releases it is included in.

 

Get Process CPU Usage Using WMI

I recently blogged about another method to obtain a process’ CPU usage via Command Line: Get CPU Usage of a Process from Command Line

Here’s a quick command line method for grabbing CPU usage of a process by process id, process name, or caption.

By Process ID

wmic path win32_perfformatteddata_perfproc_process where (IDProcess = '3488') get Name, Caption, PercentProcessorTime, IDProcess /format:list

byprocid

By Process Name

wmic path win32_perfformatteddata_perfproc_process where (Name='iexplore') get Name, Caption, PercentProcessorTime, IDProcess /format:list

byprocname

By Process Name (fuzzy)

wmic path win32_perfformatteddata_perfproc_process where (Name like '%iexp%') get Name, Caption, PercentProcessorTime, IDProcess /format:list

byprocnamefuzzy

Any processes with CPU time over 50%

wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 50) get Name, Caption, PercentProcessorTime, IDProcess /format:list

bycputime

MySQL CLI Output Formatting Tips

I’m sure you’ve seen results similar to this on a standard query:

Now, if you use the \G option (Send command to mysql server, display result vertically.):

That makes reading the output from command line really nice.

One more tidbit that I’ve found I like to do is use the \p option (Print current command.) combined with \G for reference:

Got any other tips?  Leave a comment!

Openfiles Windows XP Professional Command

First of all, there are a few tools that I’ve used in the past to show me files that certain processes have opened up.  One such tool is Process Monitor by SysInternals.  Windows XP Professional comes with a command-line tool called openfiles.

What is openfiles?

Enables an administrator to list or disconnect files and folders that have been opened on a system.

By default (I think) it’s doesn’t track open files so you will need to enable it by issuing the following command (this does add some performance overhead):

openfiles /local on

After you issue that command you are required to reboot and once you’re back in windows, execute the command without any flags:

openfiles

You’ll have an output similar (well, depending on the processes you have open) to what I have here:

ID    Process Name         Open File (Pathexecutable)
===== ==================== ==================================================
12    explorer.exe         C:\Documents and Settings\Rich
72    explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
120   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
152   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
156   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
168   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
204   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
368   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
372   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83
560   explorer.exe         C:\Documents and Settings\Rich\Desktop
568   explorer.exe         C:\..6595b64144ccf1df_1.0.2600.5581_x-ww_dfbc4fc4
584   explorer.exe         C:\Documents and Settings\All Users\Desktop
592   explorer.exe         C:\..Application Data\Microsoft\CD Burning
748   explorer.exe         C:\..6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83

Files Opened Remotely via local share points:
---------------------------------------------
INFO: No shared open files found.

You can learn more about it by issuing openfiles /? and openfiles /disconnect /?

For now, I’m still a fan of Process Monitor but this is nice when I’m in a hurry and for some reason don’t have my flash drive that has Process Monitor on it.

AIX/Unix Common Commands

AIX/Unix Commands

free			- lists available disk space
dfdb			- lists dbspaces on the system.  use ifxksh to initialize the ifx environment first
who -b			- displays last date system was rebooted
oslevel			- lists the version of the operating system
bootinfo -r 		- lists total amount of real memory installed (divide by 1024 to get MB)
startjs			- starts the job server
stopjs			- stops the job server
startvlink		- starts any interface link procedure incling Misys Vision/Optimum Charge Daemon
stopvlink		- stops any interface link procedure incling Misys Vision/Optimum Charge Daemon

Physical Volume

lspv			- lists harddisks on the system and the volume groups they are attached to
lspv -l hdisk#		- lists logical volumes on the file systems
mount			- displays currently mounted file systems
lspv physvolname	- displays information about the physical volume 'physvolname'
lspv -p physvolname	- lists physical partitions associated with this physical volume 'physvolname'
lsps -a			- lists paging space associated with physical volume  Note:  if Used=75%, you need memory

Volume Group

lsvg volgrpname		- lists details about the volume group (such as PP size, #free)
lsvg -p volgrpname	- displays name and status of physical volumes for volume group

Miscellaneous

lsdev -Cc memory	- lists all installed memory cards
lsdev -Cc adapter	- lists all interface cards installed on the system
date			- shows system date and time
errpt | more		- displays error log entries in a one-line-per-entry format
errpt -a		- displays error log in same format as the Utility menu option

Terminal

penable tty#		- directs UNIX to reset a disabled terminal
pdisable tty#		- takes terminal off-line, resets terminal settings

Spooler Commands

lptstat			- shows status of all spooled printers
lptstat -pSPxx		- shows status of a specified printer
qcan -pSPxx -xJOBx	- cancels JOB#
qcan -X			- cancels all print jobs
cancel JOB#		- cancels JOB#
stopsrc -s qdaemon	- stops qdaemon
startsrc -s qdaemon	- starts qdaemon
ps -ef | grep qdaemon	- checks to see if qdaemon is running
qmov -m SP## -8		- moves job #8 to SPxx
qmov -m SP## SP##	- moves all jobs from SP## to SP##
qmove -u userID -m SP##	- moves all jobs for userID to SP##
qhld 8			- puts job #8 on hold
qhld -P SP##		- puts all jobs for SP# on hold
qhld -r 8		- releases held job #8
qhld -r -P SP##		- releases all held jobs for SP##
qadm - USP##		- takes the specified queue to an up status
qadm -DSP##		- takes the specified queue to a down status

Printing and Viewing Files

lp SP## filename	- prints contents of file to a specific printer
cat filename | more	- prints contents of file to the screen one page at a time from the beginning of the file
more filename		- prints contents of file to the screen one page at a time
tail -# filename	- shows last # of lines of file
tail filename		- shows last 10 lines of file
printout filename	- Misys print command alias.  After typing this command, the system prompts to select a printer.