LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-29-2003, 02:08 AM   #1
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Rep: Reputation: 58
Bash script question


In a script, I would like to get how long (in seconds) the script itself has been running.

I tried:
echo $SECONDS
but it does not seem to give me the right value.

Is there an easy way to count seconds elapsed since invocation?
 
Old 05-29-2003, 06:34 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,024
Blog Entries: 54

Rep: Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766Reputation: 2766
$SECONDS is AFAIK the right way to count secs since the shell's invocation, maybe you should explain/post an example why it does not seem to give you the right value.
 
Old 05-29-2003, 07:09 AM   #3
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
Cause I am stupid...
I wrote a script like this to test $SECONDS:

ls -R /data
echo $SECONDS

It took more than a minute until the directory listing scrolled on the display, while echo printed only 7 seconds afterwards.
I thought there might be a problem, since I never used SECONDS and did not know if it is the right tool for this purpose.

Now I learned that ls finishes much before the scrolling on the display...

Thanks for your help!
 
Old 05-29-2003, 07:28 AM   #4
wvrhlu
Member
 
Registered: Mar 2003
Location: Eastern Panhandle of WV
Distribution: RH 7.3
Posts: 39

Rep: Reputation: 15
Personally, if all you need to do is know how long it took to run, why not try:

# time ls -l /data

On my machine, the output looked something like this:

# time ls -l
total 180
drwxrwxrwx 5 root root 4096 May 27 08:54 downloads
drwx------ 2 root root 4096 May 16 14:03 kde-root
drwx------ 2 root root 4096 May 29 07:56 ksocket-root
drwx------ 2 root root 4096 Mar 19 13:58 mcop-root
drwx------ 2 batkins batkins 12288 May 27 09:16 orbit-batkins
drwx------ 2 root root 16384 May 29 07:56 orbit-root
-rwxr--r-- 1 root root 38252 May 28 09:10 scrollkeeper-tempfile.0
-rwxr--r-- 1 root root 38252 May 27 15:26 scrollkeeper-tempfile.1
drwx------ 2 root root 4096 Mar 20 09:35 ssh-XX1lqQuj
drwx------ 2 root root 4096 Mar 19 10:25 ssh-XX3feA0z
drwx------ 2 root root 4096 Apr 10 09:38 ssh-XX3qPWDV
drwx------ 2 root root 4096 Mar 19 11:24 ssh-XX4uSu3h
drwx------ 2 root root 4096 Mar 19 10:43 ssh-XX8YBRqW
drwx------ 2 root root 4096 Mar 19 09:34 ssh-XXBdV5z4
drwx------ 2 root root 4096 Mar 19 12:02 ssh-XXBMSvNR
drwx------ 2 root root 4096 Mar 19 10:38 ssh-XXcHIAEF
drwx------ 2 batkins batkins 4096 Apr 26 08:41 ssh-XXjFCPE0
drwx------ 2 root root 4096 Mar 19 13:02 ssh-XXm7sqV9
drwx------ 2 root root 4096 Mar 19 11:54 ssh-XXMLAuIL
drwx------ 2 root root 4096 May 29 07:54 ssh-XXneLANh
drwx------ 2 root root 4096 Mar 19 10:53 ssh-XXs01OCD
drwx------ 2 root root 4096 Mar 19 11:45 ssh-XXt0J8LW

real 0m0.163s
user 0m0.010s
sys 0m0.020s

Is that more what you are lookign for?
 
Old 05-29-2003, 08:48 AM   #5
J_Szucs
Senior Member
 
Registered: Nov 2001
Location: Budapest, Hungary
Distribution: SuSE 6.4-11.3, Dsl linux, FreeBSD 4.3-6.2, Mandrake 8.2, Redhat, UHU, Debian Etch
Posts: 1,126

Original Poster
Rep: Reputation: 58
Thanks for the time tip, now I learned another useful unix command.

However, I need $SECOND for my goal, and - thanks to god - it works.
I only used the wrong commands to test it, and so I got misleading results (or, rather, I interpreted the results the wrong way).
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
BASH script question drj000 Programming 11 03-07-2005 10:25 PM
Bash script question deiussum Programming 6 08-14-2004 11:43 AM
bash script question djgerbavore Linux - Newbie 3 07-08-2004 03:39 PM
bash script question xscousr Programming 5 07-03-2003 05:04 PM
A bash script question J_Szucs Programming 2 05-13-2003 02:13 AM


All times are GMT -5. The time now is 01:51 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration