Monday, September 28, 2015

Trs-80 Nostalgia.

Miss the good old trs-80 III. So do I even thought about trying to find a used one but this emulator popped up and is just the ticket.


You will need to create an html file that will start the whole process up.

TRS-80.html
[code]

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="trsemu-1.4.js"></script> 
<head>
<body
onload="trsEmu.screen('scrn').button('btn').perf('graph').focus();"> 
<div id="scrn">
<canvas width="512" height="384" style="background:black">
</canvas></div><br>
<div id="graph">
<canvas width="512" height="100" style="background:black">
</canvas></div><br>
<input type="button"id="btn" value="Run"
  onClick="trsEmu.run('toggle');">
<input type="button" value="Reset"
  onClick="trsEmu.run('reset');">
<body>
<html>
[/code]

You will need to download the javascript code and put it the same folder that has the html.
$ wget http://people.cs.ubc.ca/~pphillip/trsemu-1.4.js
Then you will want to make a folder called tx in the same directory
 go into the folder and download the following files:

$ wget http://people.cs.ubc.ca/~pphillip/tx/m3.png
$ wget http://people.cs.ubc.ca/~pphillip/tx/wdot.png
$ wget http://people.cs.ubc.ca/~pphillip/tx/red.png
$ wget http://people.cs.ubc.ca/~pphillip/tx/grn.png

Do not forget to change the ownership and permissions.

You should now be able to run the html file:


Installed on my web server:




Here are some notes to look at: Should work well from a web server,

What is this?

The TRS-80 Model III is an old 8-bit home computer. This web page emulates it using only Javascript. You'll need a web browser with a fast Javascript engine. The latest (mid 2010) versions of Chrome, Safari and Opera will work well on a reasonably fast machine (2 GHz processor) Firefox will run, but not real-time, and IE is very slow (both should get faster within a year or so).
Click on the Run button to start the BASIC interpreter. You will need to press ENTER twice to get the actual BASIC ready prompt.
You can also try out a few other programs by selecting them in the table above. Note that the backslash (\) key is the TRS-80 clear key, needed to start Super Nova.
Oh, and, sorry in advance, the backspace button won't leave the page because it is too useful for deleting characters. In fact, most short-cut keys won't work as the emulator needs to intercept most key presses.

Technical Details

This emulator is really a testament to the extreme speed of modern computers and the astounding new Javascript interpreters. The combination can easily emulate the function of the TRS-80 running at 2 MHz. That's well over 100,000 emulated instructions per second! The code here came from converting the C code my twin brother wrote for trs80gp into Javascript. That would have been easy except that he used features of C (like pointers) and I had to spend some time undoing all that cleverness.
Most TRS-80 games had sound effects by using the cassette port. But this emulator doesn't have any sound effects because I don't know of a portable way to play dynamically generated sound in Javascript.
I haven't spent a great deal of time testing it although I've ran about a dozen different programs with no noticable problems.
It was a hassle to get the emulator running on a selection of browsers. Some didn't support the <canvas> tag (IE and Opera) and the workaround version using CSS sprites required a horrific amount of fiddling. There's a bit of VBScript in here to allow IE to load binary data using AJAX. And, finally, the key codes generated varies a bit from browser to browser. I could have used JQuery or some other library but doing it by myself was educational. (Although I'll admit I haven't tried to cover a very wide range of browsers at all). At one point the emulator did function using Opera for the Wii and the PS3's internal browser--but far too slow to be usable. Owners of iPads or iPhone 3GS or better should be able to get the Cass? prompt going, again, a bit slowly.
About the keyboard. The original TRS-80 keyboard is somewhat different from contemporary PC keyboards and does not support as many keys. The emulator tries to map the key you press to the appropriate TRS-80 combination. The old BREAK key is available by typing ESC and the CLEAR key is available via backslash. Here's the original keyboard layout with the shift keys. (Assuming you have a PC keyboard--but it should work pretty similar on a Macintosh)
TRS-80 keyboard layout
1  2  3  4  5  6  7  8  9  0  :  -  BK
 up Q  W  E  R  T  Y  U  I  O  P  @  lf rt
  dn A  S  D  F  G  H  J  K  L  ;  EN CL
   sh Z  X  C  V  B  N  ,  .  /  sh
           S P A C E B A R

Holding shift:

!  "  #  $  %  &  '  (  )  01 *  =  BK
 up Q  W  E  R  T  Y  U  I  O  P  `  lf rt2
  dn A  S  D  F  G  H  J  K  L  +  EN CL
   sh Z  X  C  V  B  N  <  >  ?  sh
           S P A C E B A R

Notes:
  1. Shift-Zero toggles between upper case only/lower case input. Use underscore on your keyboard to get this function.
  2. Shift-right arrow switches to 32 character wide mode.
Multiple emulators can be created on a page. Use trsEmu.mknew() to create a new emulator and then give it its own .screen(). You will have to deal with the focus, perhaps via an onclick callback. Run binaries with the trsEmu.run() command. Just pass it a URL fragment and it will load the executable from your site using AJAX. It supports the .cmd, .hex (zmac output), .3bn (system tapes) and .bas formats. The .bas format is just an ASCII text version of a BASIC program.
Version 1.3 added support for the .cas cassette tape format and binary basic programs.
The .run() command also works as a macros if the string contains one of the |, [] or {} characters. Here are the meanings (and look at this page for examples):
  • | resets the machine.
  • {filename} loads filename into memory (and executes if binary)
  • [count] delays for count frames.
  • ~ is ignored but forces macro mode.
  • other characters are typed literally to the keyboard.
For example, the following statement will reset, load foo.bas, and run it:
trsemu.run("|[1]_\r0\r[1]{foo.bas}RUN\r")
(Which, BTW, is done automatically when run is passed a string ending in .bas).

That's all

Talk to me.

 Computers are robots without arm or legs.




You may want to read this first. http://www.instructables.com/id/Text-to-speech-with-linux/ 

You may also want to setup automatic login into C1 and C2. i.e.
On C3:
$ ssh-keygen -t rsa

If .ssh directory is already setup and security is not a real issue just press return at all the prompts.

$ cd .ssh
$ scp .ssh./id_rsa.pub C1:~/.
$ scp .ssh./id_rsa.pub C2:~/.

If you have rights on C1 and C2, For C1 and C2: You will want to log into them and add the .pub file to the  authorized_keys file.

$ cd .ssh
$ cat ../id_rsa.pub > authorized_keys

Now you can login easily or send commands remotely without having to type in passwords for C3.

You could login into C2 and C1 and type the command:

$ echo this is a test | festival --tts

And you would hear This is  a test from the speakers assuming are turned on and the volume was loud enough. But we might not want to log into C2 or C1 so that To test the speakers you could issue the commands remotely and be a bit more stealthy from C3:

$  ssh C1 "echo this is a test | festival --tts"
$  ssh C2 "echo this is a test | festival --tts"

Now comes the fun part. You could set up a script file to make if appear if the computers are talking to each other. Such as simulating an argument.

Script
[code]

 ssh C1 "You messed with me | festival --tts"
 ssh C2 "echo NO, I did not. | festival --tts"
 ssh C1 "echo Yes you did | festival --tts"
 ssh C2 "echo NO, I did not. | festival --tts"
ssh C1 "echo  Yes you did | festival --tts"
 ssh C2 "echo NO, I did not. | festival --tts"
...
...

[/code]

Or you could even make an even  more interesting conversation. You get the idea!  Just be careful in case the victims at the computers might over react. Just one way to use your robots without legs.

Finally, you could add led's, a robot arm, or etc,  just like you might do with an Arduino or an RPi. So could remotely do a sort of light show.

$ ssh oeorgan1 "kitt"

And the lights sott of mimic the red lamps on the famous TV car called "Kitt".  Code for that little project is in  another post here,


The only limit is your imagination.

Sunday, September 27, 2015

Times are a changing.

Try this at your own risk!! Do not try this while the power supply is connected or plugged in.





One of the biggest changes from the old Pentium one computer to the newer personal computers is the internal power supply connector. This was a challenge for me as I wanted a dc-dc power supply for my "AT" based robot but they only readily come in atx fornat.

AT connector:



ATX connector:


Unfortunately at the time I needed a converter there was not one made commercially I could find.  You could make a sort of Rube/Goldberg pc power supply something like this:


Just did not want to go to that much trouble. So I wonder if an Atx ps would work at least for testing.  Got out the manual for the atx ps I had and started comparing notes.

AT:

ATX:
 Possible connections:


Looks like it might work, so I made a crude cable.



That evolved into the who connection:


Fortunately it worked! Had an ATX PS that it did not work with because of the missing -5v line required by the older motherboards. You can now get the pre-made cables, but if the ATX PS does not have the -5v line (most newer ATX PS boxes do not support -5v)  they more than likely will not work.

Just as a side note, Most versions of linux will not work with the Pentium 1 anymore, but Slackware will.



Saturday, September 26, 2015

Simple web server management script.

Not so long ago while  searching the web for certain cgi scripts found ths very short script in the wayback machine. Apparently the author no longer had the page, The script was twenty lines if that. The script did not seem like that much at first, but then I started adding code. You could even add other scripts to allow itself to be more powerful. The script became more and more useful. Did not fancy it up with advanced html, but it was so useful, put it on all the major servers.  An older version of the web page looks something like this:

One of the features I integrated into script was to see what ipaddresses were live on the network. That may not mean so much but if you are on a tablet, that is not and easy thing to do usually. That way you could see if there were any trespassers so to speak.


Pretty much know what the usual ip addresses are. If one was missing that meant a device was either down or not connected  A cute feature.

If you want to experiment with the script, it is at: http://www.instructables.com/id/Simple-linux-commands-from-a-web-page/

Also check out: http://www.instructables.com/id/Data-mining/

Tuesday, September 22, 2015

Install once, use many.

With the internet you can access so many applications say a cooking program to help you prepare meals.


The network configuration is pretty simple. It might look something like this:


But then you can actually set up your own home web server and the network might look something like this. I have separated the web paths from the internet and the local web server  to make things a little clearer.


Now that means you could have even more interesting web applications such as a web desktop. Some with a tablet could still generate documents without having any special applications on the tablet. You even set up many other applications without having to use the web. (http://www.instructables.com/id/Uses-for-your-own-private-cloud/)




So now you have double the pleasure. But what if your internet was cut off or you needed to limit your bandwidth. The the network might look something like this, but you would still have access to your local server. This is sometimes known as an intranet.


Sometimes this is called redundancy. You can actually duplicate sites (where allowed by law) from the net on your own systems. With what is called virtual hosts, you can have multiple completely different web sites on your local server. For example:




Really neat possibilities! One thing, I might also mention is that a lot of companies want you to put their web application on your phone or tablet. It means they truly do not understand the "cloud" concept. Those applications waste space and lessens the control and security over your devices and it's installed applications. Real web designers know how to do craft pages that will work with your tablets and phones without you having to download anything. This makes your local server so much more valuable. Also too, web server generally works just fine on older equipment. So there may be no reason to chunk that old computer.


Yes, it is a web server! To tie everything in, you can use a web applications many, times on many machines but only have to install and update it once as the need arises, Have fun!

Monday, September 21, 2015

Admin hint.

#1


Admin hint for the day. Keep a list of mac addresses for the network interfaces., Reason I say this is that people will invariably want to use their own equipment on your network i .e. using your bandwidth among other things. Usually if you only use a standard type of network interface, you can go to the dhcp server and see the nonstandard nic mac address stick out like a sore thumb allowing you to pursue the matter further. If there are no oddball mac addresses, you can also compare all network connects against the existing database. If a nic mac address does not match, your off to investigate. You could exclude the non-standard interfaces, but on a public network that is not always practical.

If something nefarious was definitely going on, we would shut down the port at the switch. But then they would know you are on to them. Takes judgment.

#2


Have seen several articles about ow MSAdmins are balking about having to use the command line. It amuses me quite a bit. Not so long ago a company called Sysinternals (since bought by Microsoft) came out with a set of commands called pstools, psexec, and etc, At that particular time., I was working for a company that had a campus of several square miles. During the summer, doing sneaker support. could be a real challenge. With the Sysinternals software,you could add, remove, and change software all from one point without running around during bad weather days, plus it saved a lot of time.

Eventually the company I worked for eventually acquired gui based software that did pretty much the same thing but was godly expensive and tremendously not foolproof, The Issues may have been resolved by now, but I have not kept up with it. Left my employer not long after that.

It is interesting now that M$ is using that kind of command line methodology with their new servers. This makes sense because you can script aka make  batch files to not only automate many tasks but easily document exactly what is done. Easily repeatable and easily do it remotely. You can then take those files and easily edit them for other tasks. You can not really do that with the mouse aka gui environment

Server upgrades.


Upgrading the operating system on your home machine is a piece of cake compared to doing it in the server environment, Generally when you care changing a server os, you use a new systems so that if there are issues you can go back to the old system as a failsafe. There are always issues setup up new operating systems especially with hardware drivers, so dealing with that can be fun.

When you set up a new system the storage formats are completely different.   Some applications will balk at that, In some cases it could be just a permissions problem. Also network printers and input devices have to be set up. Remembering once when we went from Novell to NT printing out student invoices did not work or barely worked. The consulting company said it worked when they tested it, but never really did a mass testing. We ended up pooling printers to make things work well enough till a better fix was done.

To add to that scenario, you have to make sure the general permissions of files are correctly setup. For instance, years ago everything was locked down on Novell, Microsoft there was no real security, so you had to go directory, and file by file and change as needed.

There were always server applications that did not want to work with the newer systems OS applications could and will fail, This is especially true with specific permissions access.  You will need to make adjustments to allow your applications work in the new environment. . This was even true between versions of Microsoft servers. You would have to contact vendors for fixes and updates which on many cases the vendors were reluctant to do. In many cases you had to perform miracles on your own to make things work,  That led to issues, because vendors would threaten to sue you if you changed their software for copyright and or other violations.

Once you had that done, you had to go application by application to make sure the clients interacted with the server properly. This meant you had to completely revise your control (batch, shell, etc) files because the same scripts would no longer work anymore. Then you had to go to the clients and correct shortcuts to connect to the new control files. We usually just built a new image to work with.  Then there was the testing and retesting to make sure everything worked, That was just the tip of the iceberg.. Moving on, Of course, all this had to be done without the user ever knowing a change was made.  Being a software administrator is so much fun,


Sunday, September 20, 2015

Command line search.

 
           ______  _     _  ______   _______  ______   _______  _  _  _
          / _____)(_)   (_)(_____ \ (_______)(_____ \ (_______)(_)(_)(_)
         ( (____   _     _  _____) ) _____    _____) ) _______  _  _  _
          \____ \ | |   | ||  __  / |  ___)  |  __  / |  ___  || || || |
          _____) )| |___| || |  \ \ | |      | |  \ \ | |   | || || || |
         (______/  \_____/ |_|   |_||_|      |_|   |_||_|   |_| \_____/
         Surfraw - Shell Users' Revolutionary Front Rage Against the Web

Have done a lot of web page scraping, but never was aware of a tool called surfraw. What surfraw does is takes your browser with a command line argument of your search criteria and retreives everything via the command line. You do not have to load the browser, go to the search engine and enter in the search criteria. Saves a lot of keystrokes and the results can be easily manipulated. For example say you wanted to know in wikipedia about pregnancy.

$ surfraw wikipedia what is etopic pregnancy


or 

$ sr ask why am i pregnant?

So the basic format is:

 $ surfraw [elvi] [search criteria]

Possible elvi choices are:
codesearch    -- Search source code using Google Code Search (www.google.fr/codesearch)
comlaw        -- Search Australian Law using Comlaw (www.comlaw.gov.au)
ctan        -- Search the Comprehensive TeX Archive Network (ctan.org)
currency    -- Convert currencies with the Universal Currency Converter (www.xe.net/ucc)
cve        -- Search for CAN assignments in CVE
debbugs        -- Search the debian BTS (bugs.debian.org)
debcontents    -- Search contents of debian/ubuntu packages (packages.debian.org/packages.ubuntu.com)
deblists    -- Search debian mailing lists (lists.debian.org/search.html)
deblogs        -- Show changelogs for a package in Debian main (changelogs.debian.net)
debpackages    -- Search debian/ubuntu packages (packages.debian.org/packages.ubuntu.com)
debpkghome    -- Visit the home page for a Debian package
debpts        -- Search the Debian Package Tracking System (packages.qa.debian.org)
debsec        -- Search the Debian Security Tracker for CVE ids or package names
debvcsbrowse    -- Browse the VCS repository for a Debian package
debwiki        -- Search the Debian Wikis (wiki.debian.org & women.debian.org/wiki)
deja        -- Search usenet using Google Groups (groups.google.com)
deli        -- Search Delicious bookmarks
discogs        -- Search the Discogs database of music information (www.discogs.com)
dmoz        -- Search the Open Directory Project web directory (dmoz.org)
duckduckgo    -- Securely search the web using duckduckgo (www.duckduckgo.com)
ebay        -- Search the Ebay auction site
etym        -- Look up word origins at www.etymonline.com
excite        -- Search on Excite (www.excite.com)
finkpkg        -- Search Fink packages (pdb.finkproject.org)
foldoc        -- The Free On-Line Dictionary Of Computing (foldoc.org)
freebsd        -- Search FreeBSD related information (www.freebsd.org)
freedb        -- Search for cd track listings in FreeDB (www.freedb.org)
freshmeat    -- Search Freshmeat (www.freshmeat.net)
fsfdir        -- Search the FSF/UNESCO Free Software Directory (directory.fsf.org)
gcache        -- Search the web using Google cache (www.google.com)
genbugs        -- Search the Gentoo bug tracker (bugs.gentoo.org)
genportage    -- Search gentoo-portage.com for packages
google        -- Search the web using Google (www.google.com)
gutenberg    -- Search for books on Project Gutenberg (gutenberg.org)
happypenguin    -- Search the Linux Game Tome (www.happypenguin.org)
imdb        -- Search the Internet Movie Database (www.imdb.com)
ixquick        -- Search the web using ixquick [HTTPS] (www.ixquick.com)
jamendo        -- Search Jamendo: free music with Creative Commons licenses (www.jamendo.com)
javasun        -- Search Java API docs (java.sun.com)
l1sp        -- Search lisp documentation
lastfm        -- Search last.fm
leodict        -- Search Leo's German <-> English dictionary (dict.leo.org)
lsm        -- Search the Linux Software Map
macports    -- Search macports packages (macports.org)
mathworld    -- Search Wolfram MathWorld
mininova    -- Search the mininova bittorent source.
musicbrainz    -- Search MusicBrainz (musicbrainz.org)
netbsd        -- Search NetBSD related information (www.netbsd.org)
ntrs        -- Search the NASA Technical Report Server
openbsd        -- Search OpenBSD related information (www.openbsd.org)
openports    -- search openports for OpenBSD packages
opensearch    -- Search an OpenSearch-enabled website
pasearch    -- Search the unofficial Penny Arcade archives (pipefour.org/pa)
pgpkeys        -- Search the PGP key database
piratebay    -- Search thepiratebay.org for torrents
pubmed        -- Search medical/molbio databases (www.ncbi.nlm.nih.gov)
rae        -- Busca en el diccionario de la Real Academia de la Lengua EspaƱola (Spanish Dictionary)
rfc        -- Search RFCs (internet standards documents)
rhyme        -- Search for rhymes et al using Lycos Rhyme (rhyme.lycos.com)
rpmsearch    -- Search for RPMs in various distros
scholar        -- Search Google Scholar (scholar.google.com)
scicom        -- Search Scientific Commons
scirus        -- Search for science using Scirus (scirus.com)
scitopia    -- Search for science with scitopia.org
scpan        -- Search the Comprehensive Perl Archive Network (search.cpan.org)
scroogle    -- Search Google anonymously via Scroogle (www.scroogle.org)
slashdot    -- Search stories on Slashdot (www.slashdot.org)
slinuxdoc    -- Search entries in LDP (www.linuxdoc.org)
sourceforge    -- Search SourceForge (www.sourceforge.net)
springer    -- Search Springer for Books and Articles
stack        -- Search Stack Overflow
stockquote    -- Get a single stock quote (multiple providers)
sunonesearch    -- Search Sun One Search (onesearch.sun.com)
thesaurus    -- Look up word in Merriam-Webster's Thesaurus (www.m-w.com)
translate    -- Translate human languages (various providers)
urban        -- Search urbandictionary.com for a definition
W        -- Activate Surfraw defined web-browser
w3css        -- Validate a CSS URL with the w3c CSS validator (jigsaw.w3.org/css-validator)
w3html        -- Validate a web page URL with the w3c validator (validator.w3.org)
w3link        -- Check web page links with the w3c linkchecker (validator.w3.org/checklink)
w3rdf        -- Validate a RDF URL with the w3c RDF validator (validator.w3.org)
wayback        -- Search The Internet Archive's Wayback Machine for a URL (archive.org)
webster        -- Look up word in Merriam-Webster's Dictionary (www.m-w.com)
wetandwild    -- Real time weather information (many sources)
wikipedia    -- Search the free encyclopedia wikipedia
woffle        -- Search the web using Woffle (localhost:8080)
worldwidescience    -- Search for science with www.worldwidescience.org
yahoo        -- Search Yahoo categories (www.yahoo.com)
yandex        -- Search the web using Yandex (yandex.ru)
youtube        -- Search YouTube (www.youtube.com)
yubnub        -- Use the social command-line for the web (yubnub.org)

Installation:

Arch: $ sudo pacman -S surfraw
Debian: $ sudo apt-get install surfraw

Configuration

Surfraw gets its configuration from three sources, in order:
  1. Environment variables
  2. /etc/surfraw.conf
  3. $HOME/.surfraw.conf
/etc/surfraw.conf and $HOME/.surfraw.conf are both fragments of bourne-shell style shell script.
/etc/surfraw.conf should use def and defyn to define variables. These functions set variables unless they are already set by the environment. defyn is used for boolean configuration variables, def for all others. For instance:
 def     SURFRAW_text_browser /usr/bin/lynx
 defyn   SURFRAW_graphical  no
$HOME/.surfraw.conf should use sh-style entries, eg:
 SURFRAW_text_browser=/usr/bin/lynx
 SURFRAW_graphical=no
This is because you want them to override environment variables unconditionally.

Saturday, September 19, 2015

Command line spreadsheet.

No matter what system you use or even if you do everything by hand, you will need a typewriter (editor), Filing cabinet (database), and an financial worksheet (spreadsheet). Everyone knows about vim, nano, and  for using as editor or word processor. If you have ever wanted to set up a filing cabinet or database, you probably have heard of Mysql (or one of the variants), Postgresql, or even Nosql.



What many people have not heard of is a spreadsheet for the command line.One interesting spreadsheet is called simply enough called sc. Some people may lead you to believe it will only support just numbers that is not true.



You can even get a help file with:

$ scqref > sc_commands

...
...
 A:   This overview
 B:   Toggle Options
 C:   Set Options
 D:   Cursor movement commands
 E:   Cell entry and editing commands
 F:   Line Editing
 G:   File commands
 H:   Row and column commands
 I:   Range commands
 J:   Miscellaneous commands
 K:   Variable names/Expressions
 L:   Range functions
 M:   Numeric functions
 N:   String functions
 O:   Financial functions
 P:   Time and date functions
...
...

There is even a tutorial you can use:

$ sc /usr/share/doc/sc/tutorial.sc


Though we like to use out own home grown spreadsheet called lizzyclc. Lizzyclc was created with Freebasic, so it is easy to update for adding new features.

Also the command structure is easier to follow for a new user.


Thats all..

Friday, September 18, 2015

Software Clock

Compile the following code in the qb45 or freebasic compiler.  (c:\>fbc -lang qb clock.bas). Porting to C should be a piece of cake.

[code]
 '=====================================================================
' thetimeis
' author: computothought
'---------------------------------------------------------------------
' housekeeping
' arrays
dim blank$(7)
dim num$(10,10)
dim colon$(7)

' data
num$(0, 1) = "  ###  "
num$(0, 2) = " #   # "
num$(0, 3) = "# #   #"
num$(0, 4) = "#  #  #"
num$(0, 5) = "#   # #"
num$(0, 6) = " #   # "
num$(0, 7) = "  ###  "

num$(1, 1) = "   #   "
num$(1, 2) = "  ##   "
num$(1, 3) = " # #   "
num$(1, 4) = "   #   "
num$(1, 5) = "   #   "
num$(1, 6) = "   #   "
num$(1, 7) = " ##### "

num$(2, 1) = " ##### "
num$(2, 2) = "#     #"
num$(2, 3) = "      #"
num$(2, 4) = " ##### "
num$(2, 5) = "#      "
num$(2, 6) = "#      "
num$(2, 7) = "#######"

num$(3, 1) = " ##### "
num$(3, 2) = "#     #"
num$(3, 3) = "      #"
num$(3, 4) = " ##### "
num$(3, 5) = "      #"
num$(3, 6) = "#     #"
num$(3, 7) = " ##### "

num$(4, 1) = "#      "
num$(4, 2) = "#    # "
num$(4, 3) = "#    # "
num$(4, 4) = "#######"
num$(4, 5) = "     # "
num$(4, 6) = "     # "
num$(4, 7) = "     # "

num$(5, 1) = "#######"
num$(5, 2) = "#      "
num$(5, 3) = "#      "
num$(5, 4) = " ##### "
num$(5, 5) = "      #"
num$(5, 6) = "#     #"
num$(5, 7) = " ##### "

num$(6, 1) = " ##### "
num$(6, 2) = "#     #"
num$(6, 3) = "#      "
num$(6, 4) = "###### "
num$(6, 5) = "#     #"
num$(6, 6) = "#     #"
num$(6, 7) = " ##### "

num$(7, 1) = "#######"
num$(7, 2) = "#    # "
num$(7, 3) = "    #  "
num$(7, 4) = "   #   "
num$(7, 5) = "  #    "
num$(7, 6) = "  #    "
num$(7, 7) = "  #    "

num$(8, 1) = " ##### "
num$(8, 2) = "#     #"
num$(8, 3) = "#     #"
num$(8, 4) = " ##### "
num$(8, 5) = "#     #"
num$(8, 6) = "#     #"
num$(8, 7) = " ##### "

num$(9, 1) = " ##### "
num$(9, 2) = "#     #"
num$(9, 3) = "#     #"
num$(9, 4) = " ######"
num$(9, 5) = "      #"
num$(9, 6) = "#     #"
num$(9, 7) = " ##### "

blank$(1) = "       "
blank$(2) = "       "
blank$(3) = "       "
blank$(4) = "       "
blank$(5) = "       "
blank$(6) = "       "
blank$(7) = "       "

colon$(1) = "  # "
colon$(2) = " # #"
colon$(3) = "  # "
colon$(4) = "    "
colon$(5) = "  # "
colon$(6) = " # #"
colon$(7) = "  # "

'--------------------------------------------------------------------
'the logic
cls
locate 10,2: print"                                                                            #"
locate 11,2: print"  #####  #    #  ######     #####     #    #    #  ######    #     ####    # #"
locate 12,2: print"    #    #    #  #            #       #    ##  ##  #         #    #         #"
locate 13,2: print"    #    ######  #####        #       #    # ## #  #####     #     ####"
locate 14,2: print"    #    #    #  #            #       #    #    #  #         #         #    #"
locate 15,2: print"    #    #    #  #            #       #    #    #  #         #    #    #   # #"
locate 16,2: print"    #    #    #  ######       #       #    #    #  ######    #     ####     #"
locate 17,2: print ""

locate 20,20: print colon$(1);
locate 21,20: print colon$(2);
locate 22,20: print colon$(3);
locate 23,20: print colon$(4);
locate 24,20: print colon$(5);
locate 25,20: print colon$(6);
locate 26,20: print colon$(7);

locate 20,50: print colon$(1);
locate 21,50: print colon$(2);
locate 22,50: print colon$(3);
locate 23,50: print colon$(4);
locate 24,50: print colon$(5);
locate 25,50: print colon$(6);
locate 26,50: print colon$(7);


true% = -1
while true%

hrl$ = mid$(TIME$, 1,1): minl$ = MID$(TIME$, 4, 1): secl$ = mid$(TIME$, 7,1)
hrr$ = mid$(TIME$, 2,1): minr$ = MID$(TIME$, 5, 1): secr$ = mid$(TIME$, 8,1)

' hour left
    locate 20,1: print num$(val(hrl$), 1);
    locate 21,1: print num$(val(hrl$), 2);
    locate 22,1: print num$(val(hrl$), 3);
    locate 23,1: print num$(val(hrl$), 4);
    locate 24,1: print num$(val(hrl$), 5);
    locate 25,1: print num$(val(hrl$), 6);
    locate 26,1: print num$(val(hrl$), 7);

'hour right
    locate 20,10: print num$(val(hrr$), 1);
    locate 21,10: print num$(val(hrr$), 2);
    locate 22,10: print num$(val(hrr$), 3);
    locate 23,10: print num$(val(hrr$), 4);
    locate 24,10: print num$(val(hrr$), 5);
    locate 25,10: print num$(val(hrr$), 6);
    locate 26,10: print num$(val(hrr$), 7);

'minute left
    locate 20,30: print num$(val(minl$), 1);
    locate 21,30: print num$(val(minl$), 2);
    locate 22,30: print num$(val(minl$), 3);
    locate 23,30: print num$(val(minl$), 4);
    locate 24,30: print num$(val(minl$), 5);
    locate 25,30: print num$(val(minl$), 6);
    locate 26,30: print num$(val(minl$), 7);

'minute right
    locate 20,40: print num$(val(minr$), 1);
    locate 21,40: print num$(val(minr$), 2);
    locate 22,40: print num$(val(minr$), 3);
    locate 23,40: print num$(val(minr$), 4);
    locate 24,40: print num$(val(minr$), 5);
    locate 25,40: print num$(val(minr$), 6);
    locate 26,40: print num$(val(minr$), 7);

'second left
    locate 20,60: print num$(val(secl$), 1);
    locate 21,60: print num$(val(secl$), 2);
    locate 22,60: print num$(val(secl$), 3);
    locate 23,60: print num$(val(secl$), 4);
    locate 24,60: print num$(val(secl$), 5);
    locate 25,60: print num$(val(secl$), 6);
    locate 26,60: print num$(val(secl$), 7);

'Second right
    locate 20,70: print num$(val(secr$), 1);
    locate 21,70: print num$(val(secr$), 2);
    locate 22,70: print num$(val(secr$), 3);
    locate 23,70: print num$(val(secr$), 4);
    locate 24,70: print num$(val(secr$), 5);
    locate 25,70: print num$(val(secr$), 6);
    locate 26,70: print num$(val(secr$), 7);
wend
[/code]

Tuesday, September 15, 2015

Check a server status.

(Updated with correct code. copied wrong code!)

Ever wanted to quickly whether a web server is up without going to the web page. Here is a quickie static cgi-bin script to do that. You can even check not only on local servers but most any web server on the net. The lines that do not have an ip address are virtual hosts from the last mentioned IP address. You will need to refresh the page to get the latest status.


The code is written in PHP, so PHP will need to be installed as well as the cgi-bin directory enabled. Most lamp servers have this already setup. There are probably better scripts but this one was quick and dirty.

)corrected)
[code]
 <html>
<body>

<hr>
<center>
<h2>
Web Server status
</h2>
</center>
<hr>
<br />
<table border="1" cellpadding="10">
<tr>
<td>
Ipaddress
</td>
<td>
Site (and link)
</td>
<td>
Description
</td>
<td>
Server status
</td>
</tr>
<tr>
<tr>
<td>
192.168.1.31
</td>
<td>
<a href="http://oesrvr1">Offshore Educators</a>
</td>
<td>
Old school site
</td>
<td>
<?php
if (fsockopen('oesrvr1', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>
<td>
192.168.1.32
</td>
<td>
<a href="http://oeorgan1">Offshore Educators</a>
</td>
<td>
New school site
</td>
<td>
<?php
if (fsockopen('oeorgan1', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>

<tr>
<td>

</td>
<td>
<a href="http://www.myposgarage.com">Myposgarage</a>
</td>
<td>
The store
</td>
<td>
<?php
if (fsockopen('www.myposgarage.com', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>
<td>

</td>
<td>
<a href="http://www.softserv.com">Softserv</a>
</td>
<td>
Software development
</td>
<td>
<?php
if (fsockopen('www.softserv.com', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>
<!--
<td>
<a href="http://www.myposgarage.com">Myposgarage</a>
</td>
<td>
The store
</td>

<td>
<?php
if (fsockopen('www.myposgarage.com', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
-->
</tr>
<tr>
<td>

</td>
<td>
<a href="http://www.www.thefoodhistory.com">The food history.com</a>
</td>
<td>
Food history
</td>
<td>
<?php
if (fsockopen('www.thefoodhistory.com', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>
<td>

</td>
<td>
<a href="http://www.misslizziesworld.com">Miss Lizzies world</a>
</td>
<td>
Womans world
</td>
<td>
<?php
if (fsockopen('www.misslizziesworld.com', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>
<td>

</td>
<td>
<a href="http://www.yourdrsmedicalrecords.com">Dr's office</a>
</td>
<td>
Medical office
</td>
<td>
<?php
if (fsockopen('www.yourdrsmedicalrecords.com', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>
<td>
192.168.1.33
</td>
<td>
<a href="http://oesrvr3">Offshore Educators</a>
</td>
<td>
Nslu2
</td>
<td>
<?php
if (fsockopen('oesrvr3', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>
<tr>
<td>
192.168.1.34
</td>
<td>
<a href="http://archie">Alarm</a>
</td>
<td>
Arch pogoplug
</td>
<td>
<?php
if (fsockopen('alarm', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>

<tr>
<td>
192.168.1.120
</td>
<td>
<a href="http://typo1">Typo1</a>
</td>
<td>
Pxe server
</td>
<td>
<?php
if (fsockopen('typo1', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>
</td>
</tr>

<tr>
<td>
Secret
</td>
<td>
<a href="http://www.google.com">Google</a>
</td>
<td>
Search engine
</td>
<td>
<?php
if (fsockopen('www.google.com', 80)){
echo('Online');
} else{
echo('The server is offline');
}
?>

</table>
</body>
</html>
[/code]

Monday, September 14, 2015

Chmod me.

Admin hint of the day: Understanding permissions on linux at first can be unsettling. There are several applications that you can access on-line to make it easier. If you have your own server, you can setup the application there and not be dependent on the net.

For more information see: http://catcode.com/teachmod/

Scores without the scraping.

Went to run the nfl score scraper and notice that if did not run anymore.   Found a web page that pretty much does it for you. So you can get the scores from the command line.

 links2 -dump "http://scoresline.com/scores.asp?Date=9/13/2015&F=NFL"


Sunday, September 13, 2015

linux CPU info.

 

CPU hardware information

The cpu information includes details about the processor, like the architecture, vendor name, model, number of cores, speed of each core etc. There are quite a few commands on linux to get those details about the cpu hardware, and here is a brief about some of the commands.

1. /proc/cpuinfo

The /proc/cpuinfo file contains details about individual cpu cores. Output its contents with less or cat.
$ less /proc/cpuinfo
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 23
model name      : Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz
stepping        : 10
microcode       : 0xa07
cpu MHz         : 1998.000
cache size      : 2048 KB
physical id     : 0
siblings        : 4
core id         : 0
cpu cores       : 4
apicid          : 0
initial apicid  : 0
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dtherm tpr_shadow vnmi flexpriority
bogomips        : 5303.14
clflush size    : 64
cache_alignment : 64
address sizes   : 36 bits physical, 48 bits virtual
power management:
Every processor or core is listed separately the various details about speed, cache size and model name are included in the description.
To count the number of processing units use grep with wc
$ cat /proc/cpuinfo | grep processor | wc -l
4
The number of processors shown by /proc/cpuinfo might not be the actual number of cores
on the processor. For example a processor with 2 cores and hyperthreading would be 
reported as a processor with 4 cores.
To get the actual number of cores, check the core id for unique values
$ cat /proc/cpuinfo | grep 'core id'
core id         : 0
core id         : 2
core id         : 1
core id         : 3
So there are 4 different core ids. This indicates that there are 4 actual cores.

2. lscpu

lscpu is a small and quick command that does not need any options. It would simply print the cpu hardware details in a user-friendly format.
$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 23
Stepping:              10
CPU MHz:               1998.000
BogoMIPS:              5303.14
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              2048K
NUMA node0 CPU(s):     0-3



3. hardinfo

Hardinfo is a gtk based gui tool that generates reports about various hardware components. But it can also run from the command line only if there is no gui display available.
$ hardinfo | less
It would produce a large report about many hardware parts, by reading files from the /proc directory. The cpu information is towards the beginning of the report. The report can also be written to a text file.
Hardinfo also performs a few benchmark tests taking a few minutes before the report is displayed.

4. lshw

The lshw command can display limited information about the cpu. lshw by default shows information about various hardware parts, and the '-class' option can be used to pickup information about a specific hardware part.
$ sudo lshw -class processor
  *-cpu                   
       description: CPU
       product: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz
       vendor: Intel Corp.
       physical id: 0
       bus info: cpu@0
       version: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz
       slot: LGA 775
       size: 1998MHz
       capacity: 4GHz
       width: 64 bits
       clock: 333MHz
       capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx x86-64 constant_tsc arch_perfmon pebs bts rep_good nopl aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm sse4_1 xsave lahf_lm dtherm tpr_shadow vnmi flexpriority cpufreq
The vendor, model and speed of the processor are being shown correctly. However it is not possible to deduce the number of cores on the processor from the above output.

5. nproc

The nproc command just prints out the number of processing units available. Note that the number of processing units might not always be the same as number of cores.
$ nproc
4

6. dmidecode

The dmidecode command displays some information about the cpu, which includes the socket type, vendor name and various flags.
$ sudo dmidecode -t 4
# dmidecode 2.12
SMBIOS 2.4 present.

Handle 0x0000, DMI type 4, 35 bytes
Processor Information
        Socket Designation: LGA 775
        Type: Central Processor
        Family: Pentium D
        Manufacturer: Intel(R) Corporation
        ID: 7A 06 01 00 FF FB EB BF
        Signature: Type 0, Family 6, Model 23, Stepping 10
        Flags:
                FPU (Floating-point unit on-chip)
                VME (Virtual mode extension)
                DE (Debugging extension)
                PSE (Page size extension)
                TSC (Time stamp counter)
                MSR (Model specific registers)
                PAE (Physical address extension)
                MCE (Machine check exception)
                CX8 (CMPXCHG8 instruction supported)
                APIC (On-chip APIC hardware supported)
                SEP (Fast system call)
                MTRR (Memory type range registers)
                PGE (Page global enable)
                MCA (Machine check architecture)
                CMOV (Conditional move instruction supported)
                PAT (Page attribute table)
                PSE-36 (36-bit page size extension)
                CLFSH (CLFLUSH instruction supported)
                DS (Debug store)
                ACPI (ACPI supported)
                MMX (MMX technology supported)
                FXSR (FXSAVE and FXSTOR instructions supported)
                SSE (Streaming SIMD extensions)
                SSE2 (Streaming SIMD extensions 2)
                SS (Self-snoop)
                HTT (Multi-threading)
                TM (Thermal monitor supported)
                PBE (Pending break enabled)
        Version: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz
        Voltage: 1.6 V
        External Clock: 333 MHz
        Max Speed: 4000 MHz
        Current Speed: 2666 MHz
        Status: Populated, Enabled
        Upgrade: Socket LGA775
        L1 Cache Handle: 0x0003
        L2 Cache Handle: 0x0001
        L3 Cache Handle: Not Provided
        Serial Number: Not Specified
        Asset Tag: Not Specified
        Part Number: Not Specified

7. cpuid

The cpuid command fetches CPUID information about Intel and AMD x86 processors.
The program can be installed with apt on ubuntu
$ sudo apt-get install cpuid
And here is sample output
$ cpuid

.....

Vendor ID: "GenuineIntel"; CPUID level 13

Intel-specific functions:
Version 0001067a:
Type 0 - Original OEM
Family 6 - Pentium Pro
Model 7 - Pentium III/Pentium III Xeon - external L2 cache
Stepping 10
Reserved 4

Extended brand string: "Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz"
CLFLUSH instruction cache line size: 8
Initial APIC ID: 2
Hyper threading siblings: 4

Feature flags bfebfbff:
FPU    Floating Point Unit
VME    Virtual 8086 Mode Enhancements
DE     Debugging Extensions
PSE    Page Size Extensions
TSC    Time Stamp Counter
MSR    Model Specific Registers
PAE    Physical Address Extension
MCE    Machine Check Exception
CX8    COMPXCHG8B Instruction
APIC   On-chip Advanced Programmable Interrupt Controller present and enabled
SEP    Fast System Call
MTRR   Memory Type Range Registers
PGE    PTE Global Flag
MCA    Machine Check Architecture
CMOV   Conditional Move and Compare Instructions
FGPAT  Page Attribute Table
PSE-36 36-bit Page Size Extension
CLFSH  CFLUSH instruction
DS     Debug store
ACPI   Thermal Monitor and Clock Ctrl
MMX    MMX instruction set
FXSR   Fast FP/MMX Streaming SIMD Extensions save/restore
SSE    Streaming SIMD Extensions instruction set
SSE2   SSE2 extensions
SS     Self Snoop
HT     Hyper Threading
TM     Thermal monitor
31     reserved

.....

8. inxi

Inxi is a script that uses other programs to generate a well structured easy to read report about various hardware components on the system. Check out the full tutorial on inxi.
$ sudo apt-get install inxi
Print out cpu/processor related information
$ inxi -C
CPU:       Quad core Intel Core2 Quad CPU Q8400 (-MCP-) cache: 2048 KB flags: (lm nx sse sse2 sse3 sse4_1 ssse3 vmx) 
           Clock Speeds: 1: 1998.00 MHz 2: 1998.00 MHz 3: 1998.00 MHz 4: 1998.00 MHz

Friday, September 11, 2015

Beginning graphing

One of the simplest graphs I have seen can be done in bash. You will need a data file and a one line executable to extract the data from the file and then display it.

data:
Irene     10
Karen     37
Andreas   41
Beatrice  23

Code:
SCALE=1; WIDTHL=10; WIDTHR=60; BAR="12345678"; BAR="${BAR//?/==========}"; while read LEFT RIGHT rest ; do RIGHT=$((RIGHT/SCALE)); printf "%${WIDTHL}s: %-${WIDTHR}s\n" "${LEFT:0:$WIDTHL}" "|${BAR:0:$RIGHT}*"; done < data

Result:
   Irene: |==========*                                              
   Karen: |=====================================*                       Andreas: |=========================================*               
  Beatrice: |=======================*


Another script:


 bar="=================================================="
  barlength=${#bar}
  i=0
  while ((i < 100)); do
    n=$((i*barlength / 100))       # Number of bar segments to draw $((i/2))
    printf "\r[%-${barlength}s]" "${bar:0:n}"
    ((i += RANDOM%5+2))            # i = percentage done
    sleep 1
  done
  echo

The you could get a bit more fancy with a bit of animation.

[code]
 # !/bin/sh
#
# Bargraph_Generator.sh
#
# A DEMO 6 bit coloured bargraph animation for a default Bash and Terminal window on OSX 10.7.5...
# A simple Shell script to display an _AT_A_GLANCE_ real time analogue bargraph generator. It
# starts off with GREEN for OK, then YELLOW for warning and finally ending with RED for danger
# with a critical beep for values 61 to 63 inclusive.
# It assumes an 8 bit value being injected into the script which is then divided by 4 to give
# a 6 bit value which is 64 spaces width inside the Terminal. The DEMO uses a random number
# generator to give a representation of an 8 bit value so you can see it working...
#
# A shell derivative of my Python code:-
# http://code.activestate.com/recipes/577612-seven-bit-colored-analogue-bar-graph-generator-dem/?in=user-4177147
#
# To run, ensure the script is executable and change if required, then type from a Terminal:-
#
# xxxxx$ /full/path/to/Bargrapth_Generator.sh<CR>
#
# And away you go...
#
# Written in such a way that kids and newbies can understand what is going on.
#
# Originally written for a Macbook Pro 13 inch, OSX 10.7.5 using the default Terminal.
# It MIGHT work on some Linux variants but WAS intended for MacOS OSX 10.7.x and above only.
#
# The Terminal colours WILL be changed to Black background and Various foreground colours.
# It will NOT be returned back to its original state although it can be easily. If you
# need to rerturn back to default state then there are a couple of easy methods the
# simplest being type:-
#
# xxxxx$ reset<CR>
#
# And all will be corrected...
#
# Issued entirely as Public Domain and you may do with it as you please
#
# $VER Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.
#
# Enjoy finding simple solutions to often very difficult problems...

# The required _varibales_ for ease of coding, these are the colours...
# White On Black.
WOB="\x1B[1;37;40m"
# Black On Green.
BOG="\x1B[1;30;42m"
# Black On Yellow.
BOY="\x1B[1;30;43m"
# Black On red.
BOR="\x1B[1;30;41m"
# Green On Black.
GOB="\x1B[1;32;40m"
# Yellow On Black.
YOB="\x1B[1;33;40m"
# Red On Black.
ROB="\x1B[1;31;40m"

# Set the pseudo 6 bit value to zero.
SIX_BIT_DEPTH=0

# Do a clear screen to White On Black.
printf $WOB
clear

while true
do
    # Set up the screen per scan and prepare for the bargraph.
    clear
    printf $WOB"\n \$VER: Bargraph_Generator.sh_Version_0.00.10_(C)2012_B.Walker_G0LCU.\n\n"
    printf " A horizontal, at a glance, coloured, analogue bargraph display for\n"
    printf " a default Terminal inside OSX 10.7.5..\n\n\n\n\n"
    printf "        0         10        20        30        40        50        60"
    printf $GOB"\n        +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--\n"
    printf $GOB"       (|                                                              "$ROB")\n"
    printf $GOB"        +----+----+----+----+----+----+----+----+----+"$YOB"----+----+"$ROB"----+--\n\n\n\n"
    # If the 6 bit value is 0, zero, do no more until printing the 6 bit value and generating another 6 bit value...
    # Anything greater than or equal to 1 enters this conditional branch.
    if [ "$SIX_BIT_DEPTH" -ge "1" ]
    then
        # If the 6 bit value is less than or equal to 46 then _plot_ the green section only.
        # The '\x1B[12;8f' is the ANSI 'Esc' code that forces the print position to 12 lines by 8 columns.
        if [ "$SIX_BIT_DEPTH" -le "46" ]
        then
            BARGRAPH=$GOB"\x1B[12;8f("$BOG
            for green in $(seq 1 "$SIX_BIT_DEPTH")
            do
                BARGRAPH=$BARGRAPH" "
            done
        fi
        # If the 6 bit value is greater than or equal to 47 then print the green section and _plot_ the yellow section.
        if [ "$SIX_BIT_DEPTH" -ge "47" ]
        then
            BARGRAPH=$GOB"\x1B[12;8f("$BOG"                                              "$BOY
            for yellow in $(seq 47 "$SIX_BIT_DEPTH")
            do
                BARGRAPH=$BARGRAPH" "
            done
        fi
        # If the 6 bit value is greater than or equal to 57 then print the green and yellow section and _plot_ the red section.
        if [ "$SIX_BIT_DEPTH" -ge "57" ]
        then
            BARGRAPH=$GOB"\x1B[12;8f("$BOG"                                              "$BOY"          "$BOR
            for red in $(seq 57 "$SIX_BIT_DEPTH")
            do
                BARGRAPH=$BARGRAPH" "
            done
        fi
        printf "$BARGRAPH"$GOB"\n\n\n\n\n"
    fi
    # When the 6 bit value is greater than or equal to 61 sound a system error beep.
    if [ "$SIX_BIT_DEPTH" -ge "61" ]
    then
        printf "\a"
    fi
    # Print the 6 bit value in White On Black...
    printf $WOB" Random number generated "$SIX_BIT_DEPTH"...\n\n"
    printf " Press Ctrl-C to stop the program...\n\n"
    # Generate another 6 bit value as though from an 8 bit value...
    SIX_BIT_DEPTH=$[($RANDOM % (256/4))]
    # A practical lower limit for the sleep command is 'sleep 0.05'...
    sleep 1
done

# End of Bargraph_Generator.sh DEMO.
# Enjoy finding simple solutions to often very difficult problems... ;o)

[/code]

One step farther:




 
Or then you could use a built in program such as gnuplot. It is well documented and there are a zillion examples on the web.

Here is a simple data file:

# sample 2-column data file
# -------------------------
1     1
2     4
3     9
4    16
5    25
6    36
7    49
8    64
9    81
10  100

The you want to fire up gnuplot

$ gnuplot

    G N U P L O T
    Version 4.6 patchlevel 0    last modified 2012-03-04
    Build System: Linux i686

    Copyright (C) 1986-1993, 1998, 2004, 2007-2012
    Thomas Williams, Colin Kelley and many others

    gnuplot home:     http://www.gnuplot.info
    faq, bugs, etc:   type "help FAQ"
    immediate help:   type "help"  (plot window: hit 'h')

Terminal type set to 'unknown'
gnuplot>


Set a simple terminal for now

gnuplot> set term dumb

Now let's use that data file

gnuplot> plot '2col.dat'


Or if you have Imagemagick installed you can get a bit fancier.

gnuplot> set term png
Terminal type set to 'png'
Options are 'nocrop font "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf,12" fontscale 1.0 size 640,480 '

gnuplot>               set output '| display png:-'

Then run your plot again

gnuplot> plot '2col.dat' with linespoints


Try a different data file


1,    1,   2,   5
2,    4,   4,  10
3,    9,   6,  15
4,   16,   8,  20
5,   25,  10,  25
6,   36,  12,  30
7,   49,  14,  35
8,   64,  16,  40
9,   81,  18,  45
10, 100,  20,  50
 
gnuplot> plot '4col.csv' using 1:2 with lines, '4col.csv' using 1:3 with lines
gnuplot> plot '4col.csv' using 1:2 with lines, '4col.csv' using 1:3 with lines, '4col.csv' using 1:4 with lines
 



gnuplot>               set term png
Terminal type set to 'png'
Options are 'nocrop font "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf,12" fontscale 1.0 size 640,480 '
gnuplot>               set output '| display png:-'
gnuplot> set style line 1 lc rgb "red"
gnuplot> set style line 2 lc rgb "blue"
gnuplot>
gnuplot> set style fill solid
gnuplot> set boxwidth 0.5
gnuplot>
gnuplot> plot "data.dat" every ::0::0 using 1:3:xtic(2) with boxes ls 1, \
>     "data.dat" every ::1::2 using 1:3:xtic(2) with boxes ls 2
gnuplot>





 gnuplot>               set term png
Terminal type set to 'png'
Options are 'nocrop font "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf,12" fontscale 1.0 size 640,480 '
gnuplot>               set output '| display png:-'
gnuplot>
gnuplot> set xrange [-pi/2:pi/2]; set yrange [-pi/2:pi/2]
gnuplot> set contour
gnuplot> set isosamples 100,100; set samples 100,100
gnuplot> splot sin(x)*cos(y) with lines palette linewidth 4
smooth palette in png: using 160 of 160 available color positions
gnuplot> pause -1

The sky is the limit have fun.
------------------------------------------
Update:

Each script takes in a csv file as input and “plots” the values as an ASCII graph in the terminal. It’s questionable how useful this actually is, but it’s a bit of fun at least. The SCALE variable controls the amount of characters used for the width of the plot area (not including the table containing labels and values).
Simple: Plot Values of each item
input file: sales
january,140
february,29
march,26
april,54
may,72
june,86

output: ./vgraph sales
 
 Relative Value Chart
Name      Value (Max is 140)
____________________0_________._________|_________._________|100% (140)
january      140    |========================================
february     29     |========
march        26     |=======
april        54     |===============
may          72     |====================
june         86     |========================

Percentage graph using value and max for each item

input file: stock-list
apples,20,100
pears,40,50
cherries,100,150
mangoes,45,85
tomatoes,30,30

output: ./pgraph stock-list
 
 Percentage Chart
____________________0_________._________|_________._________|100%
apples       ( 20%) |========
pears        ( 80%) |================================
cherries     ( 66%) |==========================
mangoes      ( 52%) |=====================
tomatoes     (100%) |========================================

And the scripts…. They are both very similar, just some minor tweaks to make them do what I wanted.

vgraph

 Relative Value Chart

Name      Value (Max is 140)
____________________0_________._________|_________._________|100% (140)
january      140    |========================================
february     29     |========
march        26     |=======
april        54     |===============
may          72     |====================
june         86     |========================

 
#!/bin/bash
#
# Value Graph (vgraph)
# Basic ASCII Graphing Tool
#
# Plot values and scale to max
#
# CSV format: Name, Value
#
# Awk isn't perfect at rounding.. .5 rounds down
#
# v1.1 sol@subnetzero.org

if [ -z $1 ]; then
        printf "Usage: pgraph [datafile]\n"
        exit 1
fi

# Set Vars
# FILLER and ENDDELIM are used for drawing bars.
ENDDELIM="="
FILLER="="
SCALE=40
INPUTFILE=$1
NAME=(`awk -F"," '{print $1}' < "$INPUTFILE"`)
TOTAL=(`awk -F"," '{print $2}' < "$INPUTFILE"`)

# Get Max qty for scaling
MAXQTY=0
for VALUE in ${TOTAL[*]}
do
        if [ "$VALUE" -gt "$MAXQTY" ]; then
                MAXQTY=$VALUE
        fi
done

# Make graph header and markings
printf "\n Relative Value Chart\n"
printf "\nName      Value (Max is $MAXQTY)\n"
printf "____________________0"
QTRSCALE=`echo "$SCALE / 4" | bc -l | awk '{printf("%.0f",$0)}'`
HALFSCALE=`echo "$SCALE / 2" | bc -l | awk '{printf("%.0f",$0)}'`
THRSCALE=`echo "$SCALE * 0.75" | bc -l | awk '{printf("%.0f",$0)}'`
LCNT=1
while [ "$LCNT" -le "$SCALE" ];
do
        case $LCNT in
                $QTRSCALE)      printf ".";;
                $HALFSCALE)     printf "|";;
                $THRSCALE)      printf ".";;
                $SCALE)         printf "|100%% ($MAXQTY)\n";;
                *)              printf "_";;
        esac
        LCNT=$(( $LCNT + 1 ))
done

# Draw graph bars
i=0
for ITEM in ${NAME[*]}
do
        # Print Category name in format along with info and bars
        LENGTH=`echo "scale=2;(( ${TOTAL[$i]} / $MAXQTY ) * $SCALE )" |\
                bc |\
                awk '{printf("%.0f",$0)}'`
        printf "%-12.12s %-6.6s |" "$ITEM" "${TOTAL[$i]}"
        BLOCKS=""
        while [ "$LENGTH" -gt "0" ]; do
                if [ "$LENGTH" -eq "1" ]; then
                        BLOCKS="$BLOCKS$ENDDELIM"
                else
                        BLOCKS="$BLOCKS$FILLER"
                fi
                LENGTH=$(( $LENGTH - 1 ))
        done
        printf "$BLOCKS\n"
        i=$(( $i + 1 ))
done
printf "\n\n"
 
pgraph
 
 
 ./pgraph.sh stock-list
max is 150

 Percentage Chart
____________________0_________._________|_________._________|100%
apples       ( 20%) |========
pears        ( 80%) |================================
cherries     ( 66%) |==========================
mangoes      ( 52%) |=====================
tomatoes     (100%) |========================================
 
#!/bin/bash
#
# PercentageGraph (pgraph)
# Basic ASCII Graphing Tool
#
# CSV format: Name,Used,Total (or Maximum)
#
# Awk isn't perfect at rounding.. .5 rounds down
#
# v1.1 sol@subnetzero.org

if [ -z $1 ]; then
        printf "Usage: pgraph [datafile]\n"
        exit 1
fi

# Set Vars
# FILLER and ENDDELIM are used for drawing bars.
ENDDELIM="="
FILLER="="
SCALE=40
INPUTFILE=$1
NAME=(`awk -F"," '{print $1}' < "$INPUTFILE"`)
USED=(`awk -F"," '{print $2}' < "$INPUTFILE"`)
TOTAL=(`awk -F"," '{print $3}' < "$INPUTFILE"`)

# Get Max qty for scaling
MAXQTY=0
for VALUE in ${TOTAL[*]}
do
        if [ "$VALUE" -gt "$MAXQTY" ]; then
                MAXQTY=$VALUE
        fi
done

echo "max is $MAXQTY"

# Make graph header and markings
printf "\n Percentage Chart\n"
printf "____________________0"
QTRSCALE=`echo "$SCALE / 4" | bc -l | awk '{printf("%.0f",$0)}'`
HALFSCALE=`echo "$SCALE / 2" | bc -l | awk '{printf("%.0f",$0)}'`
THRSCALE=`echo "$SCALE * 0.75" | bc -l | awk '{printf("%.0f",$0)}'`
LCNT=1
while [ "$LCNT" -le "$SCALE" ];
do
        case $LCNT in
                $QTRSCALE)      printf ".";;
                $HALFSCALE)     printf "|";;
                $THRSCALE)      printf ".";;
                $SCALE)         printf "|100%%\n";;
                *)              printf "_";;
        esac
        LCNT=$(( $LCNT + 1 ))
done

# Draw graph bars
i=0
for ITEM in ${NAME[*]}
do
        # Print Category name in format along with info and bars
        LENGTH=`echo "scale=2;(( ${USED[$i]} / ${TOTAL[$i]} ) * $SCALE )" |\
                bc | \
                awk '{printf("%.0f",$0)}'`
        PCT=`echo "scale=2;(( ${USED[$i]} / ${TOTAL[$i]} ) * 100)" |\
             bc |\
             awk '{printf("%.0f",$0)}'`
        printf "%-12.12s (%3.3s%%) |" "$ITEM" "$PCT"
        BLOCKS=""
        while [ "$LENGTH" -gt "0" ]; do
                if [ "$LENGTH" -eq "1" ]; then
                        BLOCKS="$BLOCKS$ENDDELIM"
                else
                        BLOCKS="$BLOCKS$FILLER"
                fi
                LENGTH=$(( $LENGTH - 1 ))
        done
        printf "$BLOCKS\n"
        i=$(( $i + 1 ))
done
printf "\n\n"