LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem creating a script using Rss for total consumption memory (https://www.linuxquestions.org/questions/linux-newbie-8/problem-creating-a-script-using-rss-for-total-consumption-memory-4175593967/)

nuclear95 11-21-2016 11:09 AM

Problem creating a script using Rss for total consumption memory
 
Hi,
i want to create a script that opens firefox,loads some urls from a txt file and then record some statistics such as the amount of instances that belongs to firefox and the total memory consumption(in MB) every 0.5 sec.i want the statistics to be written and saved in file.i know how to find the memory consumption ( grep /proc/"pid"/status VmRSS ) but i dont know how to do it every 0,5 sec and then write&save on file.

thank you for your time!!

Turbocapitalist 11-21-2016 11:50 AM

There is a utility named "watch" which you can use to run your script every 0.5 seconds. See its manual page for the details. You can write the output to a file using a redirection

But to convert it to RSS needs a bit more work, maybe with perl.

nuclear95 11-21-2016 12:13 PM

Thank you for your answer,but maybe you misundestood me.With Rss i mean Resident set size,not rss feed.if you can help me now i would appreciate it

Turbocapitalist 11-21-2016 12:17 PM

Ok. How far have you gotten with "watch" and redirecting its output to a file?

szboardstretcher 11-21-2016 12:24 PM

Do you want to start firefox,open the URLS,then shut firefox down completely every .5 second?

TB0ne 11-21-2016 12:29 PM

Quote:

Originally Posted by nuclear95 (Post 5633032)
Thank you for your answer,but maybe you misundestood me.With Rss i mean Resident set size,not rss feed.if you can help me now i would appreciate it

"help me NOW???"

How about reading the "Question Guidelines" first?? We will be glad to help you...but if you want it 'now', then you need to hire someone. We volunteer our time here, so telling us to help you 'now' is plain rude. Also, 'help' means that YOU do work, and tell us where you're stuck, not post what you want and expect us to hand you a script.

nuclear95 11-21-2016 12:34 PM

Quote:

Originally Posted by TB0ne (Post 5633040)
"help me NOW???"

How about reading the "Question Guidelines" first?? We will be glad to help you...but if you want it 'now', then you need to hire someone. We volunteer our time here, so telling us to help you 'now' is plain rude. Also, 'help' means that YOU do work, and tell us where you're stuck, not post what you want and expect us to hand you a script.

Sorry,i didnt mean that.i dont mean "now" as you think.(figure of speech)My fault,i didnt expressed it well.

nuclear95 11-21-2016 12:40 PM

Quote:

Originally Posted by szboardstretcher (Post 5633035)
Do you want to start firefox,open the URLS,then shut firefox down completely every .5 second?

i want to start firefox,open urls for txt file,create list with all pids of firefox,kill instances(all these on background) and i want to create a recording statistics function(or if you know a better way) that every 0.5 sec will create a list with the amount of instances that belong to firefox and the total consumption memory(with resident set size),and these data must be saved on a output file.

i am stuck on the last part with the recording function.Basically i dont know how to do it every 0.5 sec.
Thank you for your time

szboardstretcher 11-21-2016 12:42 PM

Not a problem. Looks like you probably meant something like:

Quote:

With Rss i mean "Resident set size" - not "rss feed." If you can help me, now that I've explained better, I would appreciate it.

szboardstretcher 11-21-2016 12:47 PM

If you can show the script that does the first part, we can probably help you out with the second part.

TB0ne 11-21-2016 12:48 PM

Quote:

Originally Posted by nuclear95 (Post 5633049)
i want to start firefox,open urls for txt file,create list with all pids of firefox,kill instances(all these on background) and i want to create a recording statistics function(or if you know a better way) that every 0.5 sec will create a list with the amount of instances that belong to firefox and the total consumption memory(with resident set size),and these data must be saved on a output file.

i am stuck on the last part with the recording function.Basically i dont know how to do it every 0.5 sec.
Thank you for your time

No problem...so, as asked previously; post what you have already done/written/tried, and we can assist.

rtmistler 11-21-2016 12:51 PM

Quote:

Originally Posted by Turbocapitalist (Post 5633026)
There is a utility named "watch" which you can use to run your script every 0.5 seconds. See its manual page for the details. You can write the output to a file using a redirection

But to convert it to RSS needs a bit more work, maybe with perl.

Quote:

Originally Posted by Turbocapitalist (Post 5633033)
Ok. How far have you gotten with "watch" and redirecting its output to a file?

Quote:

Originally Posted by nuclear95 (Post 5633049)
i want to start firefox,open urls for txt file,create list with all pids of firefox,kill instances(all these on background) and i want to create a recording statistics function(or if you know a better way) that every 0.5 sec will create a list with the amount of instances that belong to firefox and the total consumption memory(with resident set size),and these data must be saved on a output file.

i am stuck on the last part with the recording function.Basically i dont know how to do it every 0.5 sec.
Thank you for your time

Hi nuclear95, and welcome to LQ.

Can you please post some example output and illustrate what you have tried which gets you to this output. Please also update and indicate if you have tried the advice from Turbocapitalist?

Please note that it is difficult for persons to offer assistance for your problem if it appears that you are doing different attempts from the advice, we then have no idea which actions you are trying versus not.

Turbocapitalist also gave you a link for redirection which will help you with channeling the output of your command into a log file.

However if you have used a different command, or are writing a program to perform these actions, we have no real idea because you aren't posting any specifics about your attempts.

nuclear95 11-21-2016 12:57 PM

firefox &

while read line; do
firefox --new-tab "$line"
sleep 10s
done < /home/zografos/Desktop/urls.txt

pid=$!

sleep 30s

ps aux | grep firefox | awk '{print $2}'
sudo kill $pid

sleep 10s

ps aux | grep firefox | awk '{print $2}'
sudo kill -2 $pid

here is the 1st part of script
i forgot to mention that have to kill instances of firefox.

szboardstretcher 11-21-2016 01:03 PM

First question. Isn't:

Code:

pid=$!
Capturing the pid of 'sleep 10s' instead of the firefox command? Seems like if you wanted a pid list, you would create it in the loop so you capture each pid created.

teckk 11-21-2016 02:03 PM

Code:

#Read the file by line
while read line; do
    #Will open URL in a tab (background it)
    firefox --new-tab "$line" &
    #Sleep between tab open
    sleep 2
    #Find number of firefox PID's running, will be 1 with tabs.
    pgrep firefox | wc -l >> stats.txt
    #RAM stats to file
    free -t >> stats.txt
    #Seperatpr
    echo "------New Tab------" >> stats.txt   
#File to read
done < /home/zografos/Desktop/urls.txt

Leave out --new-tab if you want to open a new instance of firefox each time. Add whatever else you want in that loop.


All times are GMT -5. The time now is 04:43 AM.