The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Array inside an array manas_ranjan UNIX for Advanced & Expert Users 5 06-10-2008 11:25 AM
KSH Setting multiples variables with an array wolfhurt Shell Programming and Scripting 1 05-20-2008 07:00 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 05:42 AM
declare, assign variables using array, counter, loop egkumpe Shell Programming and Scripting 3 08-09-2004 07:56 AM
Array variables kavitha Shell Programming and Scripting 2 03-23-2004 06:16 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008
Registered User
 

Join Date: Jun 2006
Location: Los Angeles
Posts: 17
Getting variables into a array.

Hi ,
Im trying to monitor 2 instancesof a process on our solaris server and trying to do a notification if the returned process size is greater than 500M.
Since there are two variables returned I want to make use of arrays to check each and every variable that is stored. the issue that im facing is that how can i assign the output of 'top | grep siebmtshmw | grep -v grep | awk '{print $6}' to a array ??
if i do something like

#!/bin/bash
proc[]=top| grep siebmtshmw |awk '{print $6}'|sed 's/\%//'
echo ${proc[@]} ---Returns a wrong value

for ((i = 0 ; i < ${#proc[@]} ; i++ ))
do
echo ${proc[$i]}
*** i will put the logic to check if the variables are greater than 500***
echo $i
echo ******
done

____________________


hercule1:sadmin\>top | grep siebmtshmw | grep -v grep | awk '{print $6}'
the above command returns the below vars
344M
53M
I need to store what ever is returned by top | grep siebmtshmw | grep -v grep | awk '{print $6}' into variables of a array .

Any help/suggestion is appreciated.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 01-31-2008
Moderator
 

Join Date: Dec 2003
Location: /ksh93
Posts: 880
Here is a simple example which should help you understand what is going on

Code:
bash-3.2$ ls tp*
tp  tp1 tp2 tp3 tp4
bash-3.2$fnarray=($(ls tp*))
bash-3.2$ echo ${#fnarray[*]}
5
bash-3.2$ echo ${fnarray[2]}
tp2
Reply With Quote
  #3 (permalink)  
Old 02-06-2008
Registered User
 

Join Date: Jun 2006
Location: Los Angeles
Posts: 17
Question Bash support

Hi
Does all versions of bash support array? also in my case
proc[]=top| grep siebmtshmw |awk '{print $6}'|sed 's/\%//'
echo ${proc[@]} -- > print the list of files in directory but not the 2 processes...is this wierd ?
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:37 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0