LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 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: 982
Blog Entries: 2

Rep: Reputation: 244Reputation: 244Reputation: 244
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,495

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
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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 Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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 Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
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 Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
"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,495

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



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

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

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