Sponsored Content
Full Discussion: Making a stopwatch function
Top Forums Shell Programming and Scripting Making a stopwatch function Post 302529272 by Corona688 on Thursday 9th of June 2011 01:48:41 AM
Old 06-09-2011
Quote:
Originally Posted by ifthanwhile
Sorry, maybe I should clarify (I was at work, couldn't spend a lot of time on the forum). I want the program to print a period every 15 seconds that ping does not reach the host.
What is your system? If you have GNU ping, it can do that all by itself.
Code:
ping -w 15 -f mysite.com

Every 15 seconds, it will print one "." and backspace it if/when it gets a reply. The -c 4 will limit it to 4 pings and therefore one minute.
Quote:
Then every 60 seconds I want the second loop to print the contents of the divres which will say
"Minutes since start = ?.00
I have grep searching for ".00" because I want only the integer values when $cnt is divided by 60 anything but the minutes will show a decimal.
There's far better ways to do math in the shell, but which one you should use depends on what your system and shell is...
This User Gave Thanks to Corona688 For This Post:
 

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
Games::FrozenBubble::NetDiscover(3pm)			User Contributed Perl Documentation		     Games::FrozenBubble::NetDiscover(3pm)

Frozen-Bubble
       Copyright X 2010 The Frozen-Bubble Team

       This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2, as
       published by the Free Software Foundation.

       This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

       You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation,
       Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

NAME
Games::FrozenBubble::NetDiscover - high performance server discovery plugin for frozen bubble SYNOPSIS
my $discover = Games::FrozenBubble::NetDiscover->new( { host => "1.2.3.4", port => 1511 }, { host => "5.6.7.8", port => 1512 }, ...); while($discover->pending()) { my @servers = $discover->found(); for(my $server = 0; $server < @servers; $server++) { printf("%02i: ip %s ping %i ", $server, $servers[$server]{ip}, $servers[$server]{ping}); } $discover->work(0.1); # sit in a select loop for 100ms # update your screen, and all of that stuff, here. } DESCRIPTION
Games::FrozenBubble::NetDiscover checks a list of servers, finding their versions, ping times, and number of current clients. It uses nonblocking IO and select, to connect to multiple servers in parallel, thus reducing the total amount of time elapsed. This, in turn, allows the user to begin playing frozen bubble more quickly. :) This module is designed to be called from a GUI loop. It has to spend sit in a select loop for most of its life in order to get accurate ping times, but it will return back to your loop at intervals you specify, so you can check for keystrokes and refresh the screen and so forth. In order to get consistent results on slow dialup links, this module will only attempt to connect to one server per each 200ms. This means for 18 servers that there are 3.4 seconds of extra guaranteed lag, but it also means packets from multiple servers are less likely to bump into eachother in the queue, so ping reply times will be more reliable. In the source script, there are two configuration parameters: $number_of_pings and $time_between_connections. These are set to 2 and 0.2, respectively. These two parameters will determine the amount of bandwidth used, and the amount of time taken before the user can select a server. Assuming the user's internet connection can handle the traffic without extra latency from queueing or retransmissions, the worst case latency will be, in seconds: N*L + T*(S-1) where N = $number_of_pings L = the roundtrip time of the slowest server in the list, in seconds T = $time_between_connections S = the number of servers in the list CONSTRUCTOR
...->new ({host => "server1", port => port}, {host => "server2", port => port}, ...) Takes a list of servers as arguments. Each server argument should be a hash reference, consisting of {host => host, port => port}. Returns a Games::FrozenBubble::NetDiscover object, which can be used within a GUI loop to discover all of your servers. The host string should ideally be an IP address. A hostname string should work too, but DNS lookups will introduce extra, unpredictable latency later on. METHODS
These methods define the public API for instances of this class. found Returns a list of 0 or more servers found. Each return value is a hash reference, containing the following keys: host: the IP address of the server port: the TCP port of the server pingtimes: array reference, contains the actual result times of 4 pings ping: the average roundtrip latency of the server, in ms freenicks: the list of players connected freegames: the list of open games (not yet started) free: the number of idle clients connected to this server games: the number of clients connected to this server, who are playing games playing: the list of players in games geolocs: the geolocations of players in games name: the self-proclaimed "name" reported by the server language: the preferred language reported by the server pending Returns non-zero if we are still waiting for a response from one or more servers; returns 0 if processing is complete. work(seconds) Enters the main loop of this module. This method requires one argument, a numeric count of seconds to work for. This is expected to be a floating point decimal, for sub-second precision. Returns the number of servers pending, just like the pending method does. INTERNAL METHODS
These methods are only meant to be called from within the module. They are subject to change without notice. try_connect Attempts to connect to a server. Moves the first "not_started" server to the "pending" list, and creates a non-blocking IO::Socket::INET object for it. Updates the begin_time timestamp, to determine when the next server should be connected. server_sm(connection_number) Implements a simple state machine. Called with an index into the pending array, to indicate that data is available for reading from this server. give_up_on(connection_number, reason) Called if select reports a socket as has_exception. Also called if the server has a bogus version, times out, or we can't parse the IP address or something. Removes the entry from further processing, and emits an error message on stderr. EXPORT
None. BUGS
implement some sort of timeout, for servers which don't respond within 5 seconds. AUTHOR
Mark Glines, <mark@glines.org>. COPYRIGHT AND LICENSE
This code is donated to the frozen bubble project, www.frozen-bubble.org, so they can do whatever they want with it. Copyright is therefore assigned to those guys. perl v5.14.2 2012-06-21 Games::FrozenBubble::NetDiscover(3pm)
All times are GMT -4. The time now is 02:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy