LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 11-24-2012, 03:16 PM   #1
Satsugyo
LQ Newbie
 
Registered: Nov 2012
Posts: 4

Rep: Reputation: Disabled
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.
 
Old 11-24-2012, 03:37 PM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 981
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
xload does a graph.
 
Old 11-24-2012, 03:51 PM   #3
Satsugyo
LQ Newbie
 
Registered: Nov 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Ya I know but xload does a histogram, not a bar graph.
 
Old 11-25-2012, 12:52 AM   #4
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
https://www.linuxquestions.org/quest...-graph-861737/

http://www.linuxcertif.com/man/1/bargraph/
 
Old 11-25-2012, 01:39 AM   #5
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora
Posts: 2,109

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
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.
 
Old 11-25-2012, 08:19 AM   #6
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 8,119
Blog Entries: 11

Rep: Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240
A poor man's bar graph in Bash
 
Old 11-25-2012, 08:21 AM   #7
Satsugyo
LQ Newbie
 
Registered: Nov 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
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.
 
Old 11-25-2012, 08:50 AM   #8
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 8,119
Blog Entries: 11

Rep: Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240
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.
 
Old 11-25-2012, 09:07 AM   #9
Satsugyo
LQ Newbie
 
Registered: Nov 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Habitual View Post
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?
 
Old 11-25-2012, 05:21 PM   #10
Habitual
LQ Addict
 
Registered: Jan 2011
Posts: 8,119
Blog Entries: 11

Rep: Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240Reputation: 2240
"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?
 
Old 11-26-2012, 01:37 AM   #11
fakie_flip
Senior Member
 
Registered: Feb 2005
Location: San Antonio, Texas
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,452

Rep: Reputation: 85
Quote:
Originally Posted by Satsugyo View Post
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.
 
  


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
how can I resume a bash script after a reboot in a terminal window? ziggycat Ubuntu 3 04-07-2011 03:30 AM
unix shell script to generate a bar graph pghosh06 Linux - Newbie 4 02-10-2011 03:01 AM
Bash script to launch a terminal window on another user's desktop Excalibre Linux - Software 7 09-29-2008 02:01 AM
xlib: how to create a window without title bar mirsoft Programming 3 01-20-2008 06:49 PM
How can a bash script findout the width of the terminal window alex.e.c Linux - Software 2 10-14-2004 11:20 AM


All times are GMT -5. The time now is 05:05 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