LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 08: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, 08:42 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
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, 09:03 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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



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 03:10 PM
[SOLVED] replacing empty values in bash xeon123 Linux - Newbie 6 03-11-2011 11:12 AM
Problem displaying Bash array values. shinobi59 Programming 3 01-17-2006 05:45 PM
bash; reading values from a file km4hr Programming 16 07-28-2005 02:07 PM
bash - comparing a variable to several values davee Programming 3 05-05-2003 07:26 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:29 PM.

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
Open Source Consulting | Domain Registration