Grabbing value from command output and monitoring for changes
Hi all,
Very new to shell scripting so appreciate some help!
There is a process count that I need to monitor, I have the AIX command that gives this value and I've cleaned it up with grep/awk so it only spits out the value I'm interested in:
I need to create something to monitor this value (numerical) at given time intervals and then write to a log file when it changes, along with a timestamp.
..but now I'm stuck reading that file and comparing it to the new value. Or perhaps there's a way to continuously monitor the value and do things more efficiently?
Any help or suggestions would be much appreciated!!
Thanks,
Monty
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 [...].
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?
I assumed that your command ran a single time, though looking back at your example maybe it executes continuously.
Small changes:
The only catch to this is that your command needs to block otherwise you'll be executing a pretty tight loop and possibly taxing resources. My first example is preferred as it puts you in control of how often you execute the command that checks on the system state.
---------- Post updated at 21:22 ---------- Previous update was at 21:14 ----------
Quote:
Originally Posted by monty77
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?
I don't think it's the grep command. Can you post the output of the first few lines of just this part of your command:
I suspect that maybe the line is bar separated and not space/tab separated and thus printing $7 might be producing null output because there is no field 7. If the output is bar separated, then you can change your awk command to supply -F "|" to specify the field separator.
tmadmin - Copyright (c) 1996-1999 BEA Systems, Inc.
Portions * Copyright 1986-1997 RSA Data Security, Inc.
All Rights Reserved.
Distributed under license by BEA Systems, Inc.
Tuxedo is a registered trademark.
TMADMIN_CAT:199: WARN: Cannot become administrator.Limited set of commands available.
3
...I think there's a blank on top of the 3 that needs stripping somehow.
If I put an echo in your code:
..it doesn't show the new_value it should have read from my command.
Good -- a single shot command is much easier to deal with.
I miss read the grep -- realise now that you are ditching the 'name' line. If the value that you are interested in is always the last line, which it appears to be, then this will be better:
If there is more output following the value you want, but it is always line seven, then try this:
Have a go with one of these and see if that works.
Good -- a single shot command is much easier to deal with.
I miss read the grep -- realise now that you are ditching the 'name' line. If the value that you are interested in is always the last line, which it appears to be, then this will be better:
If there is more output following the value you want, but it is always line seven, then try this:
Have a go with one of these and see if that works.
Thanks again, either one of those might work but I went with this in the end:
..only thing that's not perfect now is that it (understandably) will always write a row to the log when you first fire it up. Any way to avoid this?
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)