Sponsored Content
Top Forums Shell Programming and Scripting A Question Regarding Timers and Output Post 302618881 by Tenuous on Wednesday 4th of April 2012 02:17:30 PM
Old 04-04-2012
Java A Question Regarding Timers and Output

Hi there. I am fairly new to scripting in BASH so please forgive my clumsy syntax and analogy as I try to explain what I am trying to accomplish.

I have a list of mundane functions that I currently call from a script file. What I wish to do is to accurately record into a log file the times that each step is taking to allow for some analysis and planning of resources as I utilize the script for more activity on more machines. I have been directed to look at the time function but find that it's usefulness is very limited if I wish to contain all of my data to one output file. Please see the example below of my understanding of how to utilize it.
Code:
/usr/bin/time -o 'output file path' 'command to execute'

However, what I wish to see is something more like the result from what code I was able to cobble together below.
Code:
LOGFILE=completed_work_`date +%F`.log
my_run_start_date=`date +%F`
my_run_start_time=`date +%H:%M`
    echo Run began on $my_run_start_date at $my_run_start_time >> $LOGFILE
master_start=`date +%s`
# do the work here
step_start=`date +%s` #timer start
    echo 1 Do some work here.;echo 1 This is what we did here. >> $LOGFILE
step_end=`date +%s` #timer end
    step_diff=`expr $step_end - $step_start`
    echo How long it took to do it : $step_start - $step_end = $step_diff >> $LOGFILE
# we can do this as many times as we need to
step_start=`date +%s` #timer start
    echo 2 Do some work here.;echo 2 This is what we did here. >> $LOGFILE
step_end=`date +%s` #timer end
    step_diff=`expr $step_end - $step_start`
    echo How long it took to do it : $step_start - $step_end = $step_diff >> $LOGFILE
# end of the work section
master_end=`date +%s`
master_diff=`expr $master_end - $master_start`
my_run_end_date=`date +%F`
my_run_end_time=`date +%H:%M`
    echo Run ended on $my_run_end_date at $my_run_end_time >> $LOGFILE
    echo Start=$master_start : End=$master_end >> $LOGFILE
master_time_elapsed=`expr $master_diff / 3600`
    echo Elapsed time = $master_time_elapsed hours >> $LOGFILE

Can anyone please assist me with a more concise and/or elegant approach to accomplishing this within a mixed Unix/Linux environment?

Last edited by Tenuous; 04-04-2012 at 05:00 PM.. Reason: Modified the script to be an entirely functional example.
 

10 More Discussions You Might Find Interesting

1. Programming

unix and timers

Hello there.. I need to know when i start indipendant timers how can i recognize which of the active timers have made timeout alarm. The number of started timers depends on the running app I'd appreciate your help Thanks in advance (0 Replies)
Discussion started by: nightcat
0 Replies

2. Programming

A question about output.

I am learning output the data to a file using "ofstream". I need to read data from a file and output the result to the other file in 2 different ways. To do that I have to provoke two functions, and they have to output the result to the same text file. My problem is: they are correct on the screen... (2 Replies)
Discussion started by: HOUSCOUS
2 Replies

3. UNIX for Dummies Questions & Answers

Question on prtdiag output ...

Hello all , This is the output of my prtdiag command ...The speed of each of the CPUs is listed below (1281 MHz ) ..That's fine ..I'm confused about the (System clock frequency: 183 MHZ ) ..What is the difference between System Clock freq and CPU freq ...THanks.. System Configuration: Sun... (5 Replies)
Discussion started by: luft
5 Replies

4. Shell Programming and Scripting

display and output...question

Hi, I have a small question about the value cannot display correctly: MSG=log fruit=apple print "No $fruit in the store" > "$MSG/fruit_message.txt" output: No $fruit in the store should be: No apple in the store AND $MSG/fruit_message.txt ----------> cannot find the... (5 Replies)
Discussion started by: happyv
5 Replies

5. Shell Programming and Scripting

Question about output to file

Hi, I am try to setup a FOR loop script to find out all the existing linux workstations in the network w/ ip address, hostname and linux version. I created a basic FOR loop script: for i in $(seq 1 254) do echo 10.72.169.$i >> result ssh -o ConnectTimeout=3 root@10.72.169.$i "hostname"... (1 Reply)
Discussion started by: beeloo
1 Replies

6. Programming

Doubts about timers in linux kernel

Hi , I am trying to learn timers in linux kernel. I am trying to write a program where I can configure a timer to tick in every 5 seconds and a function should thus exicute in every five seconds. I tried one program with the help of linux/timer.h headerfile but I couldnt get the... (4 Replies)
Discussion started by: iamjayanth
4 Replies

7. Solaris

Question on kstat output

I'm having a little trouble understanding the output I'm seeing from kstat for the "net" class. I'm seeing a lot of entries with "mac" as the name, like this. module: bge instance: 3 name: mac class: net ... (3 Replies)
Discussion started by: Midcain
3 Replies

8. Shell Programming and Scripting

Command Output Question

Hi everyone-- I'm new to these forums and shell scripting, and I'm trying to write a script that checks if a particular ip is pingable My idea was to check if the output of the command ping <some ip> -c 1 -w 1 had the string: "1 packet transmitted, 1 received"How would I go about doing this?... (2 Replies)
Discussion started by: Prodiga1
2 Replies

9. Programming

pthread_mutex_timedlock and Timers option

in its man-page pthread_mutex_timedlock documents that the absolute timeout parameter should be based on the CLOCK_REALTIME clock or in the system clock. All this depending on whether the 'Timers option' is supported or not. What do they mean by 'Timers option'? How could I tell for sure what... (8 Replies)
Discussion started by: ramestica
8 Replies

10. Shell Programming and Scripting

INPUT/OUTPUT question

Hi All, Is it wrong to do something like this: ssh -T $PROXY_USER@$PROXY_SERVER < script.txt > ssh_output.log I ran and it works fine and does what I need. I wanted to pass a set of commands to the ssh session and store an output in the log file. Thanks (4 Replies)
Discussion started by: rdogadin
4 Replies
env(1)								   User Commands							    env(1)

NAME
env - set environment for command invocation SYNOPSIS
/usr/bin/env [-i | -] [name=value...] [ utility [ arg... ]] /usr/xpg4/bin/env [-i | -] [name=value...] [ utility [ arg... ]] DESCRIPTION
The env utility obtains the current environment, modifies it according to its arguments, then invokes the utility named by the utility op- erand with the modified environment. Optional arguments are passed to utility. If no utility operand is specified, the resulting environment is written to the standard output, with one name=value pair per line. /usr/bin If env executes commands with arguments, it uses the default shell /usr/bin/sh (see sh(1)). /usr/xpg4/bin If env executes commands with arguments, it uses /usr/xpg4/bin/sh (see ksh(1)). OPTIONS
The following options are supported: -i | - Ignores the environment that would otherwise be inherited from the current shell. Restricts the environment for utility to that specified by the arguments. OPERANDS
The following operands are supported: name=value Arguments of the form name=value modify the execution environment, and are placed into the inherited environment before utility is invoked. utility The name of the utility to be invoked. If utility names any of the special shell built-in utilities, the results are unde- fined. arg A string to pass as an argument for the invoked utility. EXAMPLES
Example 1: Invoking utilities with new PATH values The following utility: example% env -i PATH=/mybin mygrep xyz myfile invokes the utility mygrep with a new PATH value as the only entry in its environment. In this case, PATH is used to locate mygrep, which then must reside in /mybin. ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment variables that affect the execution of env: LANG, LC_ALL, LC_CTYPE, LC_MES- SAGES, and NLSPATH. PATH Determine the location of the utility. If PATH is specified as a name=value operand to env, the value given shall be used in the search for utility. EXIT STATUS
If utility is invoked, the exit status of env is the exit status of utility. Otherwise, the env utility returns one of the following exit values: 0 Successful completion. 1-125 An error occurred. 126 utility was found but could not be invoked. 127 utility could not be found. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: /usr/bin +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ /usr/xpg4/bin +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWxcu4 | +-----------------------------+-----------------------------+ |CSI |enabled | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
ksh(1), sh(1), exec(2), profile(4), attributes(5), environ(5), standards(5) SunOS 5.10 2 Jan 2002 env(1)
All times are GMT -4. The time now is 12:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy