LoadRunner Date/Time Functions

LoadRunner stores date/time parameters locally on the LoadRunner PC. This means that opening a script on another users PC, where the date/time parameter is not stored, can cause corruption to the date/time parameters in a script. You know that this has happened when a date/time parameter in this format [%Y%m%d%H%M%S] is sent to the server rather than the format that you intended.

Due to this problem, I recommend that the lr_save_datetime function is used to save date or time values to a string. The string can then be used in the script and the script is portable between PCs because we are no longer relying on the locally stored parameters.

Sample code

lr_save_datetime(“%d/%m/%y”, DATE_NOW, “DDMMYY”);
lr_output_message(“Today’s Date is %s”,lr_eval_string(“{DDMMYY}”));

lr_save_datetime(“%d/%m/%Y”, DATE_NOW, “DDMMYYYY”);
lr_output_message(“Today’s Date is %s”,lr_eval_string(“{DDMMYYYY}”));

lr_save_datetime(“%B %d %Y”, DATE_NOW, “Today”);
lr_output_message(“Today is %s”,lr_eval_string(“{Today}”));

lr_save_datetime(“%B %d %Y”, DATE_NOW + ONE_DAY, “Tomorrow”);
lr_output_message(“Tomorrow is %s”,lr_eval_string(“{Tomorrow}”));

lr_save_datetime(“%A”, DATE_NOW – ONE_DAY, “Yesterday”);
lr_output_message(“Yesterday was %s”,lr_eval_string(“{Yesterday}”));

lr_save_datetime(“%A”, DATE_NOW, “Today”);
lr_output_message(“Today is %s”,lr_eval_string(“{Today}”));

lr_save_datetime(“%A”, DATE_NOW + ONE_DAY, “Tomorrow”);
lr_output_message(“Tomorrow is %s”,lr_eval_string(“{Tomorrow}”));

lr_save_datetime(“%X”, TIME_NOW , “Time”);
lr_output_message(“The time is %s (in this locale’s date format)”,lr_eval_string(“{Time}”));

lr_save_datetime(“%X”, TIME_NOW + ONE_HOUR , “Time”);
lr_output_message(“In one hour it will be %s”,lr_eval_string(“{Time}”));

lr_save_datetime(“%A”, DATE_NOW + ONE_DAY, “Tomorrow”);
lr_output_message(“Tomorrow is %s”,lr_eval_string(“{Tomorrow}”));

lr_save_datetime(“%j”, DATE_NOW, “Today”);
lr_output_message(“Today is day %s in the year”,lr_eval_string(“{Today}”));

lr_save_datetime(“%Z”, DATE_NOW, “TimeZone”);
lr_output_message(“This machine is in the ‘%s’ time zone”,lr_eval_string(“{TimeZone}”));

lr_save_datetime(“%p”, DATE_NOW, “AMPM”);
if (strcmp (lr_eval_string(“{AMPM}”),”PM”)!=0)
{
lr_output_message(“Good Morning”);
}
else
lr_output_message(“Good Afternoon”);

UNIX command reference


Environment Control

Command                     Description
cd d                             Change to directory d
mkdir d                        Create new directory d
rmdir d                         Remove directory d
mv f1 [f2...] d               Move file f to directory d
mv d1 d2                      Rename directory d1 as d2
passwd                         Change password
alias name1 name2       Create command alias (csh/tcsh)
alias name1="name2"    Create command alias (ksh/bash)
unalias name1[na2...]    Remove command alias na
ssh nd                          Login securely to remote node
exit                              End terminal session
setenv name v              Set env var to value v (csh/tcsh)
export name="v"           Set environment variable to value v (ksh/bash)


Output, Communication, & Help

Command                     Description
lpr -P printer f               Output file f to line printer
lp -d printer f                Output file f to line printer
script  [f]                      Save terminal session to f
exit                              Stop saving terminal session
mailx username             Send mail to user
man name                     Unix manual entry for name


Process Control

Command                     Description
CTRL/c *                      Interrupt processes
CTRL/s *                      Stop screen scrolling
CTRL/q *                      Resume screen output
sleep n                         Sleep for n seconds
jobs                             Print list of jobs
kill %                           Kill job n
ps                                Print process status stats  
kill  -9 n                       Remove process n
CTRL/z *                      Suspend current process
stop  %n                      Suspend background job n
cmmd&                        Run cmmd in background
bg  [%n]                      Resume background job n
fg  [%n]                       Resume foreground job n
exit                              Exit from shell


Environment Status

Command                     Description
ls  [d]  [f...]                  List files in directory
ls -1  [f...]                    List files in detail
alias  [name]                Display command aliases
printenv  [name]           Print environment values
quota                           Display disk quota
date                             Print date & time
who                              List logged in users
whoami                        Display current user
finger  [username]        Output user information
chfn                             Change finger information
pwd                              Print working directory
history                          Display recent commands
! n                               Submit recent command n


File Manipulation

Command                     Description
vi  [f]                            Vi fullscreen editor
emacs  [f]                     Emacs fullscreen editor
ed  [f]                          Text editor
wc  f                             Line, word, & char count
cat  f                            List contents of file
more  f                         List file contents by screen
cat f1 f2 >f3                  Concatenates f1 & f2 into f3
chmod mode f               Change protection mode of f
cmp f1 f2                      Compare two files
cp f1 f2                         Copy file f1 into f2
sort f                            Alphabetically sort f
split  [-n]  f                   Split f into n-line pieces
mv f1  f2                      Rename file f1 as f2
rm f                             Delete (remove) file f
grep 'ptn'  f                  Outputs lines that match ptn
diff f1 f2                       Lists file differences
head f                          Output beginning of f
tail f                            Output end of f


Abbreviations used in this document

CTRL/x       hold down control key and press x
d               directory
env            environment
f                filename
n               number
nd             computer node
prtr            printer
ptn            pattern
var            variable
[y/n]         yes or no
[]             optional arg
...             list


Use VBS script to “kill” a process on a remote server

You can use this VBS script to kill a running process on your local machine or a remote one. As a performance tester, I have found this useful since it allows me to kill the Mercury Agent Process (magentproc.exe) on remote LoadRunner generators.

Save the text below as a file called “ProcessKill.vbs” and run it to kill the agent process on your own machine.  You just need to change the strProcessKill and strComputer strings to determine the process that you want to kill and the machine where you want to kill it. By default the script runs on the local machine “.”


Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill
strComputer = “.”
strProcessKill = “‘magentproc.exe'”

Set objWMIService = GetObject(“winmgmts:” _& “{impersonationLevel=impersonate}!” & strComputer & “rootcimv2”)

Set colProcess = objWMIService.ExecQuery _(“Select * from Win32_Process Where Name = ” & strProcessKill )

For Each objProcess in colProcess
objProcess.Terminate()
Next
WSCript.Echo “Just killed process ” & strProcessKill _& ” on ” & strComputer
WScript.Quit