Sponsored Content
Top Forums Shell Programming and Scripting How to implement stopwatch in bash? Post 302147557 by jonwiz on Tuesday 27th of November 2007 02:07:08 PM
Old 11-27-2007
bash stopwatch

I found a simple stopwatch script, and then modified it to display the time on one line. (before it was echoing the time every loop in the terminal - a waste of space)

Enjoy!

Code:
#!/bin/bash

BEGIN=$(date +%s)
BACK="\b\b\b\b"


echo Starting Stopwatch...

while true; do
        NOW=$(date +%s)
        let DIFF=$(($NOW - $BEGIN))
        let MINS=$(($DIFF / 60))
        let SECS=$(($DIFF % 60))

#only echo count if its different than the last time
if [ "$DIFF" != "$OLDDIFF" ]
then
        #backspace 4 times to reset stopwatch position
        #The '-e' enables \b to be interpreted correctly
        #The '-n' avoids the newline character at the end
        echo -ne $BACK
        echo -ne $MINS:`printf %02d $SECS`
fi

#define olddiff to current diff
let OLDDIFF=DIFF

done

 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how can i implement rlogin

how can i use a rlogin with out entered a password, someone tell me about configure the next files /.rhosts /etc/hosts.equiv and /etc/hosts but i not sure about that, or there are not enough could you tell me how to do that? (3 Replies)
Discussion started by: jav_v
3 Replies

2. Programming

how does va_arg implement ?

1 . How does va_arg implemented by system? (2 Replies)
Discussion started by: chenhao_no1
2 Replies

3. Shell Programming and Scripting

PERL: Stopwatch + record

Is it possible to make a perl or cgi script that does the following ? 1) have a stopwatch with a start / start / pause feature and record the time its paused on. but be able to record up to ten different times 2)print the recorded time to .txt file (1 Reply)
Discussion started by: perleo
1 Replies

4. AIX

how to implement timer

anyone can help me how to implement the timer on AIX? I tried with 'setitimer' and its related functions, but it does not work correctly,the program exited each time. thanks (2 Replies)
Discussion started by: Frank2004
2 Replies

5. Shell Programming and Scripting

how to implement this

Hi all, could any of you please help me on my problem.. we are doing FTP (one report out put) from one server to another server through unix shell script program. Due to the network issues, some times FTP process is hanging. So we planned to modify the existing program with the following... (2 Replies)
Discussion started by: kishore_jasthi
2 Replies

6. Shell Programming and Scripting

Trying to implement 'more' command

Hi all, i'm quite new in the UNIX world. So maybe i'm going to ask simple questions but they are unsolvable for me... I'm trying to implement the 'more' function or kinda of that, for improving my knowledges. But I encountered some problems that i hope u will help me to solve. The code i... (0 Replies)
Discussion started by: Cellofan
0 Replies

7. Solaris

new - How i can implement Mirroring

Unix is something new for me, I trying learn about it now. I have download the sun virtualbox software and install solaris 10 into it. It is is like wizard with step by step installation guideline. :) NOw how can i implement mirroring(RAID) into the my new SunOS? can anyone give a briefly list... (14 Replies)
Discussion started by: webster5u
14 Replies

8. Shell Programming and Scripting

How to implement this?

hi i have a file like 1,"A","B" 2,"C","D" 1,"E","F" 3,"G","H" in output i need like 3,"G","H" 1,"E","F" 2,"C","D" 1,"A","B" (12 Replies)
Discussion started by: angel12345
12 Replies

9. Shell Programming and Scripting

Making a stopwatch function

#The first part of this works fine a period prints every 15 seconds (ping –c 3, takes 2 seconds). However no “Minutes since start = “ message prints. #By all rights it should print 2 times once when it is outputted from “grep” and a second time when cat reads it. I would use cron but I am not... (4 Replies)
Discussion started by: ifthanwhile
4 Replies

10. Programming

Implement ps command in C

Hello, could anybody explain how the ps command works? I know something about the proc file system. But I'm still not sure about how it exactly works. Like ps without any option will print out the current user's processes, but it never displays my web browsers such as firefox or my LibreOffice... (3 Replies)
Discussion started by: freedombird9
3 Replies
STAG-DIFF(1p)						User Contributed Perl Documentation					     STAG-DIFF(1p)

NAME
stag-diff - finds the difference between two stag files SYNOPSIS
stag-diff -ignore foo-id -ignore bar-id file1.xml file2.xml DESCRIPTION
Compares two data trees and reports whether they match. If they do not match, the mismatch is reported. ARGUMENTS -help|h shows this document -ignore|i ELEMENT these nodes are ignored for the purposes of comparison. Note that attributes are treated as elements, prefixed by the containing element id. For example, if you have <foo ID="wibble"> And you wish to ignore the ID attribute, then you would use the switch -ignore foo-ID You can specify multiple elements to ignore like this -i foo -i bar -i baz You can also specify paths -i foo/bar/bar-id -parser|p FORMAT which parser to use. The default is XML. This can also be autodetected by the file suffix. Other alternatives are sxpr and itext. See Data::Stag for details. -report|r ELEMENT report mismatches as they occur on each element of type ELEMENT multiple elements can be specified -verbose|v used in conjunction with the -report switch shows the tree of the mismatching element OUTPUT If a mismatch is reported, a report is generated displaying the subpart of the tree that could not be matched. This will look like this: REASON: no_matching_node: annotation no_matching_node: feature_set no_matching_node: feature_span no_matching_node: evidence no_matching_node: evidence-id data_mismatch(:15077290 ne :15077291): evidence-id AND evidence-id Due to the nature of tree matching, it can be difficult to specify exactly how trees do not match. To investigate this, you may need to use the -r and -v options. For the above output, I would recommend using stag-diff -r feature_span -v ALGORITHM Both trees are recursively traversed... see the actual code for how this works The order of elements is not important; eg <foo> <bar> <baz>1</baz> </bar> <bar> <baz>2</baz> </bar> </foo> matches <foo> <bar> <baz>2</baz> </bar> <bar> <baz>1</baz> </bar> </foo> The recursive nature of this algorithm means that certain tree comparisons will explode wrt time and memory. I think this will only happen with very deep trees where nodes high up in the tree can only be differentiated by nodes low down in the tree. Both trees are loaded into memory to begin with, so it may thrash with very large documents AUTHOR Chris Mungall cjm at fruitfly dot org SEE ALSO
Data::Stag perl v5.10.0 2008-12-23 STAG-DIFF(1p)
All times are GMT -4. The time now is 09:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy