LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to create a bash script that creates a bar graph in the terminal window (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-create-a-bash-script-that-creates-a-bar-graph-in-the-terminal-window-4175438565/)

Satsugyo 11-24-2012 03:16 PM

how to create a bash script that creates a bar graph in the terminal window
 
Hey, I just want to know how you would go about making a bash script that creates a bar graph in the terminal window. This is a real time bar graph of cpu load average times that updates at a specified interval. I know you use the uptime command but not completely sure how to go about making the bar graph. Any help would be appreciated, thanks.

linosaurusroot 11-24-2012 03:37 PM

xload does a graph.

Satsugyo 11-24-2012 03:51 PM

Ya I know but xload does a histogram, not a bar graph.

fakie_flip 11-25-2012 12:52 AM

https://www.linuxquestions.org/quest...-graph-861737/

http://www.linuxcertif.com/man/1/bargraph/

AwesomeMachine 11-25-2012 01:39 AM

bar makes a progress bar. gnuplot may have such functionality. In any event, you're probably looking for a ncurses-based program, if that helps narrow the search.

Habitual 11-25-2012 08:19 AM

A poor man's bar graph in Bash

Satsugyo 11-25-2012 08:21 AM

https://scs.senecac.on.ca/~john.selm...123/ass02.html

The output should look something like this. The colours aside, I just want to know how you would code a bar graph like that to run in the terminal.

Habitual 11-25-2012 08:50 AM

Well, if that page is from the actual course, then clues have been provided about how to achieve this goal.

"Linux commands which display the load average include uptime, w, top and xload"
...
"Hints: besides viewing the man pages for uptime, w, top and xload you may want to investigate"

  • the stty command
  • the setterm command
  • how to print unicode characters in a Linux terminal
  • labs 7 and 8 of course
  • how to use 256 colour terminals
  • unicode table
Please let us know.

Satsugyo 11-25-2012 09:07 AM

Quote:

Originally Posted by Habitual (Post 4836562)
Well, if that page is from the actual course, then clues have been provided about how to achieve this goal.

"Linux commands which display the load average include uptime, w, top and xload"
...
"Hints: besides viewing the man pages for uptime, w, top and xload you may want to investigate"

  • the stty command
  • the setterm command
  • how to print unicode characters in a Linux terminal
  • labs 7 and 8 of course
  • how to use 256 colour terminals
  • unicode table
Please let us know.

I understand that you use the uptime,w,top commands for the data for load averages, but what I wanted to know was how exactly would you go about creating the bar graph in the terminal while the script is running. Just the base of the actual graph, everything else I can do because he gave us hints where to look. For example would you use a loop to create the horizontal lines,vertical lines and scale on the side?

Habitual 11-25-2012 05:21 PM

"For this assignment you will design and code a new BASH command (script) named "cload". The purpose of "cload" is to display a colourful bar graph, in a terminal window, of the three Linux load averages in "real" time. The three load averages are the 1 minute average, the 5 minute average and the 15 minute average."

It does NOT say you have to create the bar graph in bash, it says "display a colourful bar graph, in a terminal window".

I know what it looks like he's asking. There are variables I am not aware of, sorry.

Back on task, what have you coded so far?

fakie_flip 11-26-2012 01:37 AM

Quote:

Originally Posted by Satsugyo (Post 4836571)
I wanted to know was how exactly would you go about creating the bar graph in the terminal while the script is running.

Not sure I understand your question. You want the graph to be updated in real time? You'd need to draw the graph inside a loop, so that each time the loop would be redrawn and the commands to get the load average would be called again. You're drawing the graph with a loop, then you'd have a nested loop.

Otherwise, make it more clear with specific details what you're asking.


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