Sponsored Content
Full Discussion: Making a stopwatch function
Top Forums Shell Programming and Scripting Making a stopwatch function Post 302529167 by Corona688 on Wednesday 8th of June 2011 05:07:59 PM
Old 06-08-2011
Let's follow the logic here.

Code:
cnt=0
while [ $cnt -lt 600 ]
 do

    while [ $cnt -lt 300 ]
     do
      echo .
      # Instead of opening pinglog$$.txt n/15 times, redirect the
      # while loop itself, so you only open it once.
      ping -c 3 not_connected_IP#>>/tmp/pinglog$$.txt
      sleep 13
      ((cnt=cnt+15))
      # Jumps back up to the top of the loop if cnt is less than 300.
     done >> /tmp/pinglog$$.txt

    # to reach here, the while loop must have ended.  Therefore, 
    # cnt is already >= 300.  So this next while loop never happens.
    while [ $cnt -lt 300 ]
     do
      echo -n "Minutes since start = " > divres
      echo "scale=2; $cnt/60" | bc >> divres

#      this is a Useless Use of Cat.  http://partmaps.org/era/unix/award.html
#      grep doesn't need cat's help.
#
#      You should also use grep -q so grep doesn't try print matching lines.
#      Also:  Are you trying to match a literal dot?  dots mean 'any character'
#      grep.  Escape it with a backslash to make it match only the dot char.
#      if cat divres | grep .00
       if grep -q "\.00" < divres
       then
        echo
        cat divres
      fi
     done

     # Loops back to the beginning of the first while loop whenever
     # cnt is less than 600.
     # But cnt will never be greater than 300 because your inner
     # while loops stop doing anything past 300.
     # so this becomes an infinite loop!
 done
rm -r /tmp/pinglog$$.txt

I don't know how to simplify or fix a lot of this since I don't know what you were actually trying to do with it either.
 

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

How to implement stopwatch in bash?

I want to time how long it takes to run some programmes and report the delta time in days, hours, minutes and seconds using a simple echo. Does someone have a simple bash script to do this? Thanks, siegfried (2 Replies)
Discussion started by: siegfried
2 Replies

3. Shell Programming and Scripting

Passing global variable to a function which is called by another function

Hi , I have three funcions f1, f2 and f3 . f1 calls f2 and f2 calls f3 . I have a global variable "period" which i want to pass to f3 . Can i pass the variable directly in the definition of f3 ? Pls help . sars (4 Replies)
Discussion started by: sars
4 Replies

4. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

5. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

6. UNIX for Dummies Questions & Answers

Making a function

I am practicing making my own functions in bash for an upcoming exam. For this example, I want to print out a message and maybe add two numbers. What I would do then is: bash-3.2$ function practice { #code to print #code to add } This would be run using an input file, that would... (1 Reply)
Discussion started by: Midwest Product
1 Replies

7. Shell Programming and Scripting

Will files, creaetd in one function of the same script will be recognized in another function?

Dear All. I have a script, which process files one by one. In the script I have two functions. one sftp files to different server the other from existing file create file with different name. My question is: Will sftp function recognize files names , which are created in another... (1 Reply)
Discussion started by: digioleg54
1 Replies

8. Shell Programming and Scripting

Need help on awk for printing the function name inside each function

Hi, I am having script which contains many functions. Need to print each function name at the starting of the function. Like below, functionname() { echo "functionname" commands.... } I've tried like below, func=`grep "()" scriptname | cut -d "(" -f1` for i in $func do nawk -v... (4 Replies)
Discussion started by: Sumanthsv
4 Replies

9. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies
gnotime(1)							 The GNOME Project							gnotime(1)

NAME
gnotime - GnoTime - a time tracker SYNOPSIS
gnotime [--display displayname] [--geometry geometry] DESCRIPTION
GnoTime is a simple combination of a stopwatch, a to-do-list organizer and time-keeping/billing system. In its simplest mode of operation, as a stopwatch, it simply counts the number of elapsed seconds while the timer is running. Unlike ordi- nary stopwatches, it will keep a log of each time that the timer was started and stopped. The log, or 'journal', can be annotated with comments, allowing a diary of events to be kept. GnoTime functions as a billing system by allowing you to assign a value to an hour's worth of time. You can specify overtime, double-over- time rates and fixed flat-fees. Individual chunks of time as 'billable', 'not-billable', 'no-charge', 'hold', and so on. GnoTime can also be used as a simple to-do list tracker. You can assign an urgency as well as an importance to a given project, assign an estimated start and end date, specify a sizing and a percent-complete value. Clicking on column headings will sort the list in the order of that column. Custom reports can be created using standard HTML enhanced with embedded Scheme (a LISP -like programming language). OPTIONS
--display specifies the X server that gnotime should connect to. Refer to the X(1x) manual page for more info. --geometry specifies the geometry of the main window. The syntax [WIDTHxHEIGHT][(+|-)X(+|-)Y] is just like the X toolkit option geometry. See X(1x) for more info. OTHER TYPES OF DOCUMENTATION
You can find more information about GnoTime and its functions in the Gnome help system. Just select Contents from the Help menu to get there. SEE ALSO
X(1x), the GnoTime Online Help, the GNOME Online Help. AUTHOR
Copyright (C) 1997,1998 Eckehard Berns Copyright (C) 2001 Linas Vepstas <linas@linas.org> GNOME
12 Oct 2001 gnotime(1)
All times are GMT -4. The time now is 12:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy