LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2012, 09:33 AM   #1
julirio
LQ Newbie
 
Registered: Oct 2012
Posts: 3

Rep: Reputation: Disabled
summinf values in bash


hi! i'm trying to get all the regular files opened by all the processes in the current session. I have this code

while read pid
do

FILES_ACTUAL=$(lsof -p $pid | grep REG | wc -l)


done < <(ps -o pid,tt -u $USER | grep $CURRENT_TERMINAL | awk '{print $1}')

echo $FILES_ACTUAL

but i dont know how to add up, inside the while, the variable $FILES_ACTUAL.. I tried to use the awk command, but i couldnīt do it.
 
Old 10-10-2012, 09:42 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,483

Rep: Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425Reputation: 2425
Code:
SUM=0
while read pid
do

FILES_ACTUAL=$(lsof -p $pid | grep REG | wc -l)
SUM=$(( SUM + FILES_ACTUAL ))

done < <(ps -o pid,tt -u $USER | grep $CURRENT_TERMINAL | awk '{print $1}')

echo $FILES_ACTUAL
echo $SUM
something like this may help
 
Old 10-10-2012, 10:03 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,421

Rep: Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815Reputation: 2815
Some other suggestions for your code:
Code:
SUM=0
while read pid
do

FILES_ACTUAL=$(lsof -p $pid | grep -c REG)
(( SUM ++ FILES_ACTUAL ))

done < <(ps -o pid,tt -u $USER | awk -vct="$CURRENT_TERMINAL" '$2 ~ ct{print $1}')

echo $FILES_ACTUAL # not sure the point of showing the last value this was set to??
echo $SUM
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Get values from property file using bash samadm Programming 5 10-06-2012 04:10 PM
[SOLVED] replacing empty values in bash xeon123 Linux - Newbie 6 03-11-2011 12:12 PM
Problem displaying Bash array values. shinobi59 Programming 3 01-17-2006 06:45 PM
bash; reading values from a file km4hr Programming 16 07-28-2005 03:07 PM
bash - comparing a variable to several values davee Programming 3 05-05-2003 08:26 AM


All times are GMT -5. The time now is 06:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration