Sponsored Content
Special Forums Windows & DOS: Issues & Discussions How to log current timestamp inside a for loop in windows shell? Post 302386473 by ilan on Tuesday 12th of January 2010 01:52:54 PM
Old 01-12-2010
How to log current timestamp inside a for loop in windows shell?

below is the output where i'm getting the same times tamp throughout the loop., where i'm expecting that to log the current time stamp..
Code:
C:\Users\ilango>for /l %i in (1,1,5) do echo [%DATE% %TIME%]  for %i

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 1
[Wed 01/13/2010  0:00:57.44]  for 1

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 2
[Wed 01/13/2010  0:00:57.44]  for 2

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 3
[Wed 01/13/2010  0:00:57.44]  for 3

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 4
[Wed 01/13/2010  0:00:57.44]  for 4

C:\Users\ilango>echo [Wed 01/13/2010  0:00:57.44]  for 5
[Wed 01/13/2010  0:00:57.44]  for 5

C:\Users\ilango>


---------- Post updated at 12:22 AM ---------- Previous update was at 12:07 AM ----------

Ok, found a solution myself..

Code:
C:\Users\ilango\test>for /l %i in (1,1,5) do (VER | TIME | FINDSTR /R /C:"[0-9]"
) & echo for %i

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 1
The current time is:  0:24:46.78
for 1

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 2
The current time is:  0:24:46.82
for 2

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 3
The current time is:  0:24:46.87
for 3

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 4
The current time is:  0:24:46.90
for 4

C:\Users\ilango\test>(VER   | TIME   | FINDSTR /R /C:"[0-9]" )  & echo for 5
The current time is:  0:24:46.95
for 5

C:\Users\ilango\test>

but still, i don't understand why the earlier one didn't work!!?

Last edited by Scott; 01-12-2010 at 04:31 PM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

C Shell - Command Inside a Loop

I have a command nested in some while loops to parse some data that looks something like this. while ($condition) while ($condition) ... gzcat /dir/$fileName.gz | grep $searchString > out_file end end On the first loop, the command is executed properly (and takes maybe 10... (3 Replies)
Discussion started by: hobbers
3 Replies

2. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

3. Shell Programming and Scripting

How to retrieve the current timestamp?

I am doing this in my script .. currenttimestamp=`db2 "select current timestamp from SYSIBM.SYSDUMMY1 with ur"` echo s $currenttimestamp but this is how its shows s 1 -------------------------- 2011-04-18-12.43.25.345071 1 record(s) selected. How can I just get the timestamp... (6 Replies)
Discussion started by: mitr
6 Replies

4. Shell Programming and Scripting

help in running while loop inside a shell script

I have an input file at ./$1.txt with content of seq numbers like : 1234567890 1234589700 . . so on.. I need to take each seq nbr from the input file ,run the query below: select ackname,seqnbr from event where event_text like '%seqnbr( from the input file)' and redirect the... (11 Replies)
Discussion started by: rkrish
11 Replies

5. Shell Programming and Scripting

How to pass current year and month in FOR LOOP in UNIX shell scripting?

Hi Team, I have created a script and using FOR LOOP like this and it is working fine. for Month in 201212 201301 201302 201303 do echo "Starting the statistics gathering of $Month partitions " done But in my scripts the " Month " variable is hard-coded. Can you please any one... (3 Replies)
Discussion started by: shoan
3 Replies

6. Shell Programming and Scripting

If else condition inside for loop of awk command in UNIX shell scripting

Hi , Please excuse me for opening a new thread i am unable to find out the syntax error in my if else condition inside for loop in awk command , my actual aim is to print formatted html td tag when if condition (True) having string as "failed", could anyone please advise what is the right... (2 Replies)
Discussion started by: karthikram
2 Replies

7. Shell Programming and Scripting

To check timestamp in logfile and display lines upto 3 hours before current timestamp

Hi Friends, I have the following logfile. Currently time in india is 07/31/2014 12:33:34 and i have the following content in logfile. I want to display only those entries which contain string 'Exception' within last 3 hours. In this case, it would be the last line only I can get the... (12 Replies)
Discussion started by: srkmish
12 Replies

8. Shell Programming and Scripting

Detect current shell inside a script

I wish to print my current shell which happens to be bash in my script check.sh more check.sh echo $0 echo `ps -p $$` But instead of printing it prints check.sh i.e the name of the script for both the commands. Can you please suggest how to print the current shell i m on inside the... (2 Replies)
Discussion started by: mohtashims
2 Replies

9. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

10. UNIX for Beginners Questions & Answers

How to write a Boolean variable which succeed and failed inside the if loop in shell script ?

I have if loop with multiple variable value check in if loop. How can i print only if loop satisfied variable and its value in shell script ? I dont want to check each variable in if loop. That makes my script larger. if ] then echo "Only satisfied variable with value" ... (3 Replies)
Discussion started by: prince1987
3 Replies
All times are GMT -4. The time now is 12:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy