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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
05-29-2003, 02:08 AM
|
#1
|
|
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:
|
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?
|
|
|
|
05-29-2003, 06:34 AM
|
#2
|
|
Moderator
Registered: May 2001
Posts: 24,964
|
$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.
|
|
|
|
05-29-2003, 07:09 AM
|
#3
|
|
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:
|
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!
|
|
|
|
05-29-2003, 07:28 AM
|
#4
|
|
Member
Registered: Mar 2003
Location: Eastern Panhandle of WV
Distribution: RH 7.3
Posts: 39
Rep:
|
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?
|
|
|
|
05-29-2003, 08:48 AM
|
#5
|
|
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:
|
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).
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:39 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|