The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 02:25 PM
KSH Setting multiples variables with an array wolfhurt Shell Programming and Scripting 1 05-20-2008 10:00 AM
create array holding characters from sring then echo array. rorey_breaker Shell Programming and Scripting 5 09-28-2007 08:42 AM
declare, assign variables using array, counter, loop egkumpe Shell Programming and Scripting 3 08-09-2004 10:56 AM
Array variables kavitha Shell Programming and Scripting 2 03-23-2004 10:16 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-31-2008
vivsiv vivsiv is offline
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.
  #2 (permalink)  
Old 02-01-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,913
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
  #3 (permalink)  
Old 02-06-2008
vivsiv vivsiv is offline
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 ?
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0