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.
However, what I wish to see is something more like the result from what code I was able to cobble together below.
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.
The script relies heavily on date +%s which is not valid in unix. Please describe what value you expect from this command.
Writing totally portable code for unix and Linux is extremely difficult and nigh on impossible if you start with bash on a random Linux computer with extensions to the "date" command. Please be a bit more specific about what Operating Systems and versions are involved here and what is the preferred Bourne-type Shell on each Operating System.
You have to find the lowest common denominator and work with that. If they are ALL modern computers, the current Posix standard is recommended by many posters here.
Could you show what you actually want, instead of code you don't want?
Thanks for your reply. I didn't say, "I don't want the code." The code actually works quite well. I want to know if there is a better or more elegant way to go about doing what I did in the code I listed. I've made a quick edit so it runs as it stands and gives you the example output you requested... ---------- Post updated at 04:19 PM ---------- Previous update was at 03:58 PM ----------
Quote:
Originally Posted by methyl
The script relies heavily on date +%s which is not valid in unix. Please describe what value you expect from this command.
Please see the above post.
Quote:
Originally Posted by methyl
Writing totally portable code for unix and Linux is extremely difficult and nigh on impossible if you start with bash on a random Linux computer with extensions to the "date" command. Please be a bit more specific about what Operating Systems and versions are involved here and what is the preferred Bourne-type Shell on each Operating System.
After reviewing the requirements to answer your question, the heavy lifting is all being done from Red Hat machines.
Quote:
Originally Posted by methyl
You have to find the lowest common denominator and work with that. If they are ALL modern computers, the current Posix standard is recommended by many posters here.
Except for not being sure of what your definition of 'modern' is, I understand what your saying and am already working from that approach.
Alright, I had a bit of a go and here are a couple of ideas you could try..
As others have noted: date '%s' is a GNU extension and does not function on many platform. Your best bet may be to use perl :
of which a basic version is available on many platforms these days
You could put that into a function, since you are using it a lot:
The nice thing about this is, that you only need to replace the content of the function if you wish to use another method to obtain epoch time, for example with date '%s'
The other thing that you can change is to use a general redirection that also includes stderr (Or maybe at a later stage you wish to only use std err):
Further I replaced backticks everywhere with $(..) and expr statement with $(( ... ))
This leads to this script:
There is a bit of repetition for every step. You could reduce that for example like this:
And so forth... Apart from the call to perl this is all POSIX shell code...
This User Gave Thanks to Scrutinizer For This Post:
@Tenuous
If all the systems are Red Hat Linux, shell script compatibility with unix is academic.
The date command is not part of bash but is key to your original script.
Scrutinizer's approch with Perl is much better because of modern Perl's support for date manipulation.
Beautiful! I will be diving in deeper tomorrow and will incoporate your suggestions.
---------- Post updated at 05:55 PM ---------- Previous update was at 05:53 PM ----------
@methyl it's a mish mash of alot of systems. More than 90% are Red Hat or Solaris. It's a new job for me and I am learning alot of stuff as I go. Thanks for your input though. It is invaluable to fellows such as myself.
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)