Sponsored Content
Top Forums Shell Programming and Scripting Grabbing value from command output and monitoring for changes Post 302447616 by monty77 on Monday 23rd of August 2010 09:13:43 PM
Old 08-23-2010
Quote:
Originally Posted by agama
Try something like this:

Code:
last_value=x
log_file=/tmp/log.file
while true
do
   your-command-string | read new_value
   if [[ $last_value != $new_value ]]
   then
       echo "$(date) $new_value" >>$log_file
       last_value=$new_value
   fi
   sleep 300      # every 5 minutes
done

This assumes bash -- most modern UNIXes link /usr/bin/sh to bash -- the [[ expression on the if are much more efficient. If AIX doesn't link to bash, and/or ksh isn't available, you'll have to use if [...].
Thanks!! Looking good, however I think there's a problem with my command as it seems to be pulling blanks instead of the value I want. I put an echo $new_value in there to prove this and sure enough it's blank.

How do I use grep -vE (or something else if more appropriate) to strip and blanks from my command output and just catch the value itself?

Thanks!
Monty
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Grabbing result of sql command

Hi guys, Is there a way a script can run an SQL statement and dump the results into a variable which can then be used later in the script? Thanks. (3 Replies)
Discussion started by: hern14
3 Replies

2. UNIX for Dummies Questions & Answers

Grabbing a value from an output file

I am executing a stored proc and sending the results in a log file. I then want to grab one result from the output parameters (bolded below, 2) so that I can store it in a variable which will then be called in another script. There are more details that get printed in the beginning of the log file,... (3 Replies)
Discussion started by: hern14
3 Replies

3. UNIX for Dummies Questions & Answers

File Missing When Grabbing Files from SFTP Server using SCP Command

Hi, I have this problem where sometimes my files would go missing when I schedule my crontab to run the SCP command to get file from the SFTP server. My crontab will run the scripts at an interval of 3 minutes (between the two scripts) The following is the setting in my crontab. ... (1 Reply)
Discussion started by: gingervitus
1 Replies

4. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies

5. Solaris

Monitoring the output of 'top' command on hourly basis.

I need to capture the following data on an hourly basis through cronjob scheduling:- 1. load averages 2. Total no. of processes. 3. CPU state 4. Memory 5. Top 3 process details. All the above information is available through the command 'top'. But here we need to automate the same and... (4 Replies)
Discussion started by: subharai
4 Replies

6. Infrastructure Monitoring

AIX monitoring tools for graphical output

Hi , I am new for Aix i am using IBM AIX server in our org. I am using tomcat and JDK 1.6 for our own ERP software the data base was stored in another server (windows ) i want to monitor my AIX server with graphical output from another system it is possible please help me, any other... (7 Replies)
Discussion started by: krishna_vnr`
7 Replies

7. Shell Programming and Scripting

script to mail monitoring output if required or redirect output to log file

Below script perfectly works, giving below mail output. BUT, I want to make the script mail only if there are any D-Defined/T-Transition/B-Broken State WPARs and also to copy the output generated during monitoring to a temporary log file, which gets cleaned up every week. Need suggestions. ... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

8. Shell Programming and Scripting

Grabbing IP and zonename from multiline 'ifconfig' output

Hi There, I have a Solaris server that has a bunch of zones configured and I am trying to write a script that will take all interfaces other than the loopback ones (e.g. lo0:3 etc) and present them so that I can easily determine the zone that owns the IP So in the case of the following... (2 Replies)
Discussion started by: hcclnoodles
2 Replies

9. Shell Programming and Scripting

Grabbing value from file and run command in ``

Hi ALL, How can I make a script take data from a file and execute the commands within `` in the file n put that that in a variable? for i in `cat file` do file=`grep -i key file` cp ${file} test done file /tmp/`date +y`log /tmp/unix`date +y`log (1 Reply)
Discussion started by: 3junior
1 Replies

10. Shell Programming and Scripting

Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place. What I need The following command is placed at the prompt: TICLI... (4 Replies)
Discussion started by: jbrass
4 Replies
TIMER_SETTIME(2)					     Linux Programmer's Manual						  TIMER_SETTIME(2)

NAME
timer_settime, timer_gettime - arm/disarm and fetch state of POSIX per-process timer SYNOPSIS
#include <time.h> int timer_settime(timer_t timerid, int flags, const struct itimerspec *new_value, struct itimerspec * old_value); int timer_gettime(timer_t timerid, struct itimerspec *curr_value); Link with -lrt. Feature Test Macro Requirements for glibc (see feature_test_macros(7)): timer_settime(), timer_gettime(): _POSIX_C_SOURCE >= 199309L DESCRIPTION
timer_settime() arms or disarms the timer identified by timerid. The new_value argument is an itimerspec structure that specifies the new initial value and the new interval for the timer. The itimerspec structure is defined as follows: struct timespec { time_t tv_sec; /* Seconds */ long tv_nsec; /* Nanoseconds */ }; struct itimerspec { struct timespec it_interval; /* Timer interval */ struct timespec it_value; /* Initial expiration */ }; Each of the substructures of the itimerspec structure is a timespec structure that allows a time value to be specified in seconds and nanoseconds. These time values are measured according to the clock that was specified when the timer was created by timer_create() If new_value->it_value specifies a nonzero value (i.e., either subfield is nonzero), then timer_settime() arms (starts) the timer, setting it to initially expire at the given time. (If the timer was already armed, then the previous settings are overwritten.) If new_value->it_value specifies a zero value (i.e., both subfields are zero), then the timer is disarmed. The new_value->it_interval field specifies the period of the timer, in seconds and nanoseconds. If this field is nonzero, then each time that an armed timer expires, the timer is reloaded from the value specified in new_value->it_interval. If new_value->it_interval specifies a zero value then the timer expires just once, at the time specified by it_value. By default, the initial expiration time specified in new_value->it_value is interpreted relative to the current time on the timer's clock at the time of the call. This can be modified by specifying TIMER_ABSTIME in flags, in which case new_value->it_value is interpreted as an absolute value as measured on the timer's clock; that is, the timer will expire when the clock value reaches the value specified by new_value->it_value. If the specified absolute time has already passed, then the timer expires immediately, and the overrun count (see timer_getoverrun(2)) will be set correctly. If the value of the CLOCK_REALTIME clock is adjusted while an absolute timer based on that clock is armed, then the expiration of the timer will be appropriately adjusted. Adjustments to the CLOCK_REALTIME clock have no effect on relative timers based on that clock. If old_value is not NULL, then it returns the previous interval of the timer (in old_value->it_interval) and the amount of time until the timer would previously have next expired (in old_value->it_value). timer_gettime() returns the time until next expiration, and the interval, for the timer specified by timerid, in the buffer pointed to by curr_value. The time remaining until the next timer expiration is returned in curr_value->it_value; this is always a relative value, regardless of whether the TIMER_ABSTIME flag was used when arming the timer. If the value returned in curr_value->it_value is zero, then the timer is currently disarmed. The timer interval is returned in curr_value->it_interval. If the value returned in curr_value->it_interval is zero, then this is a "one-shot" timer. RETURN VALUE
On success, timer_settime() and timer_gettime() return 0. On error, -1 is returned, and errno is set to indicate the error. ERRORS
These functions may fail with the following errors: EFAULT new_value, old_value, or curr_value is not a valid pointer. EINVAL timerid is invalid. timer_settime() may fail with the following errors: EINVAL new_value.it_value is negative; or new_value.it_value.tv_nsec is negative or greater than 999,999,999. VERSIONS
These system calls are available since Linux 2.6. CONFORMING TO
POSIX.1-2001 EXAMPLE
See timer_create(2). SEE ALSO
timer_create(2), timer_settime(2), timer_getoverrun(2), time(7) COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. Linux 2009-02-20 TIMER_SETTIME(2)
All times are GMT -4. The time now is 05:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy