Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8069165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:56:01+00:00 2026-06-05T12:56:01+00:00

I have a bash script that tracks memory usage over time as a command

  • 0

I have a bash script that tracks memory usage over time as a command is run. It spawns the desired command and then writes a log with column1 = “memory in use by program (gigs)” and column 2 is the time elapsed so far in seconds. e.g.

31.282 1470
31.565 1480
31.848 1490
31.989 1500
32.273 1510
32.414 1520
32.697 1530
32.980 1540
33.122 1550
33.405 1560
6.511 1570
6.935 1580
7.502 1590
7.926 1600
8.351 1610
8.775 1620
9.059 1630
9.483 1640
9.908 1650
10.333 1660

What I want to do is wait until the process is complete and then use R to plot a graph of memory usage over time and save it in the current directory. I was playing around with R and I know exactly what commands I need to use:

> heisenberg <- read.csv(file="4644.log",head=FALSE,sep=" ")
> plot(heisenberg$V2,heisenberg$V1,type="o",col="red",main="Memory Usage Over Time",xlab="Time (seconds)",ylab="Memory (gigabytes)")
> text(max(heisenberg$V2),max(heisenberg$V1),max(heisenberg$V1)) #Displays max value

But the part I am stuck on is saving the graph as a jpg or png. Or how I could execute this command within my bash script. Would I absolutely need to have another script written in R language and run it? Would this be possible to do all in one?


Edit


Here is the code for my script.r

png("mem_usage_2965.png",height=800,width=800)
heisenberg <- read.csv(file="2965.log",head=FALSE,sep=" ")
plot(heisenberg$V2,heisenberg$V1,type="o",col="red",main="oases_k85",xlab="Time (seconds)",ylab="Memory (gigabytes)")
text(max(heisenberg),max(heisenberg),max(heisenberg))
dev.off()

Can anyone help as to why the text doesn’t print the maximum value in the outputted png? I am calling it in a bash script like R CMD BATCH script.r script.out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:56:02+00:00Added an answer on June 5, 2026 at 12:56 pm

    Wrap your plot calls in:

    jpeg("myplot.jpg")
    ....plot code here....
    dev.off()
    

    or

    png("myplot.png")
    ....plot code here....
    dev.off()
    

    See their respective help pages: ?png for details of other arguments.

    For a PNG this would be:

    png("my_plot.png", height = 800, width = 600)
    plot(heisenberg$V2,heisenberg$V1,type="o",col="red",main="Memory Usage Over Time",xlab="Time (seconds)",ylab="Memory (gigabytes)")
    text(max(heisenberg$V2),max(heisenberg$V1),max(heisenberg$V1)) #Displays max value
    dev.off()
    

    As for running this in a bash script, you need to invoke R to run your script containing the R code to load the data and draw the plots. For this there are several options, two are:

    R CMD BATCH --no-save --no-restore my_script.R
    

    or use Rscript

    Rscript my_script.R
    

    where my_script.R is a text file containing syntactically-valid R code required to produce the plots.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Bash script that builds a string to run as a command
I have a bash script that I need to write my password to run
I have a bash script that tries to call pgrep with arguments (Over simplified):
I have a bash script that I am run to check to see if
I have a bash script that runs (something like) the following command: vim -E
I have a bash script that uploads a file via SFTP, with a command
I have bash script that takes in a couple of arguments tests then and
I have a bash script that includes the command: mv old.txt new.txt Old.txt doesn't
I have a bash script that performs makes and then aborts when a make
I have a bash script that I want to be quiet when run without

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.