1837004 Members
2034 Online
110111 Solutions
New Discussion

script question

 
SOLVED
Go to solution
Holger Knoppik
Valued Contributor

script question

Hi all,
again i need your help. i am currently working on some scripts, which should log with timestamps. i.e.:
-(snip)----------------
#!/bin/sh
PATH=/usr/bin:/usr/sbin
TIMESTAMP=`date +"%d.%m.%E %H:%M:%S"

echo "NOTE: $0 START AT ${TIMESTAMP}"

echo "NOTE: $0 END AT ${TIMESTAMP}"
-(snip)----------------
The output i want to see are different times between start of the script and end, like:
NOTE: <script> START AT 25.10.2001 19:09:03
NOTE: <script> END AT 25.10.2001 19:11:31
My problem is that the timestamps are absolutely equal. What am i doing wrong ?
TIA, RGDS, Holger
Live long and prosper!
10 REPLIES 10
Curtis Larson_1
Valued Contributor
Solution

Re: script question

you set your timestamp with the start time then never update it with the ending time

TIMESTAMP=`date +"%d.%m.%E %H:%M:%S"

echo "NOTE: $0 START AT ${TIMESTAMP}"


#add here:
#TIMESTAMP=`date +"%d.%m.%E %H:%M:%S"
echo "NOTE: $0 END AT ${TIMESTAMP}"
Craig Rants
Honored Contributor

Re: script question

Use a TIMESTAMP and TIMESTAMP1, you can assign them the same date format, they will just get called at a different time. That should be an easy fix.

"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Craig Rants
Honored Contributor

Re: script question

Here is what I mean!

#!/bin/sh
PATH=/usr/bin:/usr/sbin
TIMESTAMP=`date +"%d.%m.%E %H:%M:%S"
TIMESTAMP1=`date +"%d.%m.%E %H:%M:%S"
echo "NOTE: $0 START AT ${TIMESTAMP}"

echo "NOTE: $0 END AT ${TIMESTAMP1}"

That's what I would do, but there are a million ways to do it.
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
linuxfan
Honored Contributor

Re: script question

Hi,

You are using the displaying the valu of TIMESTAMP,

calculate the value of timestamp after your commands

Eg:

TIMESTAMP=`date +"%d.%m.%E %H:%M:%S"

echo "NOTE: $0 START AT ${TIMESTAMP}"

TIMESTAMP=`date +"%d.%m.%E %H:%M:%S"
echo "NOTE: $0 END AT ${TIMESTAMP}"

This should fix it

-Regards
Ramesh
They think they know but don't. At least I know I don't know - Socrates
S.K. Chan
Honored Contributor

Re: script question

You can also do this ..

echo NOTE: $0 START AT `date +"%d.%m.%E %H:%M:%S"`

Eileen Millen
Trusted Contributor

Re: script question

you can also use the timex command to find out
how long something takes to run.

(eg) timex ls

Eileen
Joseph C. Denman
Honored Contributor

Re: script question

Hi Holger,

easy fix
Change the `` to '' to assign TIMESTAME to the command.

TIMESTAMP='date +"%d.%m.%E %H:%M:%S"'

Then in your echo command excute TIMESTAMP like:

echo "start `$TIMESTAMP`"

echo "end `$TIMESTAMP`"

Hope this helps.

...jcd...



If I had only read the instructions first??
Holger Knoppik
Valued Contributor

Re: script question

Hi all, happy logger working on scripts again!
ONE problem, MANY solutions.
Craig, your suggestion sounds good, i tried it but unfortunately it didn't work. HMMMM, strange...
Eileen, attractive command. I will check it out again! Thanx everybody.
RGDS, Holger
Live long and prosper!
Craig Rants
Honored Contributor

Re: script question

Holger,
I will have to look at my logic. I may have tried to answer the question before my second cup of coffee!
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Craig Rants
Honored Contributor

Re: script question

As a few others have suggested move the TIMESTAMP1 variable down after the , section and it will work fine. Oh sweet caffeine.
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut