Richard Parmiter

Virtualisation blog and Knowledge Base

  • You are here: 
  • Home
  • cmd

Script variable trimming

Posted on May 8th, 2009

Suppose you are trying to run some scripts based on a command line variable, but the variable being passed to it is surrounded by quote marks.

i.e. “device_name” when all i want is device_name

There is an easy way to trim this. In the script need to set this passed variable to a seperate variable, and then trim it byt doing the following:

SET tempvariable=%1                 (need to set %%1 if its run as a script file)

echo %1                                      (will show “device_name”)

echo %tempvariable%                 (will show “device_name”)

echo %tempvariable:~1,-1%       (will show device_name)

The trimmed variable can then be used for another task, i.e. to start a service on a remote server

sc \\%tempvariable:~1,-1% start “ServiceName”

Happy trimming!

Tags: , , , , , , , , , , ,
Filed under Scripts/Reg | 1 Comment »

Create date stamped log files

Posted on August 9th, 2008

Use the following to create date stamped log files

for /F “tokens=2,3,4 delims=/ ” %%i in (‘date /t’) do set datefile=%%i%%j%%k.log
Query User > %datefile%

Place in a cmd batch file and run on a schedule to create the logs.

Tags: , , , , , ,
Filed under Scripts/Reg | No Comments »

Ads

Ads