Skip to main content

ASCII Lineart

I have a tendency to create documentation locally using Markdown. The reason(s) why are complicated, and beyond the scope of this post, but this is a conscious choice I've made when i'm creating posts (locally) before I upload them to Confluence (or on my personal site using Nikola).

However, even when I'm doing this, I've found incompatibilities between some of the tools on my system. One example was I created some documentation, but then wanted to include a list of directories (to further explain the documentation). I created my notes in ReText and then used the tree -d command to get a list of directories, redirecting the list to a text file to be included in my text.

This worked well, and in ReText I had to set the directory listing up as pre-formatted text so it would render correctly as a mono-spaced font in my documentation.

However, when I ran the code through pandoc (using the command line pandoc -o readme.html readme.md the code came through as unicode and higher order characters that made the documentation unreadable in a web browser.

Looking carefully at the HTML, it appeared it was only interpreting the resulting output as straight ASCII and the line drawing characters from tree -d seemed to be interpreted as some other higher order character.

On a whim, I checked to see if I could change the characterset for the HTML file by adding the following line into the HTML:

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

Opening an editor on the HTML file and adding that line at the top ensured that my HTML would render correctly (or at least close enough) when I pasted in the ASCII line art that I was satisfied. Then I could grab the rendered HTML from the file and paste it into a Confluence page. Problem solved!

References:

nikola - https://getnikola.com/

pandoc - http://linux.die.net/man/1/pandoc

retext - http://sourceforge.net/projects/retext/

tree - http://linux.die.net/man/1/tree

Migrating to Nikola

I decided I wanted to migrate away from Drupal but I still wanted something similar to manage my blog content. However, I also wanted something to be able to format code for the times I wanted to publish source code of SQL, Shell Scripts. Python or whatever.

My first stop was to look at Markdown (used in places like github). And there were a variety of products that supported Markdown (aka MD) including Hyde, Jekyll, Octopress, Pelican, Sphinx, and Nikola.

http://mashable.com/2014/08/28/static-website-generators/#CDkgQ_3hgkkB

https://iwantmyname.com/blog/2014/05/the-updated-big-list-of-static-website-generators-for-your-site-blog-or-wiki.html

I was in the middle of learning Python so I chose to focus on Pelican and Nikola since they were both written in python. I felt that if there were any issues, I could at least debug the source code of either generator and fix it myself. Both had a series of plug-ins that would give me flexibility to extend the capabilities.

As I looked into Markdown, I was impressed with the features and how using a simple text editor I could create content for my blog and still make it somewhat "pretty" by adding some limited formatting commands (things like italics, lists, and bolding text) as well as the ability to include pictures (or diagrams). So having settled on using either Pelican or Nikola, I started with Pelican (it seemed to be more popular) and created some blog posts and created the blog to view it. It looked pretty good, but I couldn't display the "gallery" of pictures I was looking at. This was probably user error on my part, but I could never figure out how to render the sample pictures I wanted. So I attempted to do the same things with Nikola and it was more successful for me after a quick test.

As I played with Nikola, before I rolled it out onto my primary web site, I discovered that Nikola supports reStructured Text (RST). This was very similar to Markdown, but it allowed some extensions to support things like syntax highlighting (color coding source code to make it more readable). This really sounded like what I was looking for.

It took some time, but I finally converted most of my blog over to RST and published it to my web server. My main page now loads in about 300ms and my formatting is a lot simpler.

Leaving Drupal

Once upon a time, I used Drupal for my blog. One of the reasons I used Drupal is that I subscribe to the philosophy of "eating my own dogfood." One of the organizations I volulnteered with had a need for a website and, after some discussion, the ability to manage their own content. Drupal seemed to meet the needs at the time. This was because there weren't a lot of (mature) tools (back then) for managing blogs (other than Wordpress) and content.

So I used Drupal for several blogs and helped some friends setup their own blogs. And I used it through multiple versions of Drupal Version 5, Version 6, and Version 7 with different modules as my needs changed. However, I started to notice that some of my content looked different than older content.started to look slightly different. I used both fckeditor and TinyMCE for some formatting, as well as editing content through several different themes which may have impacted the formatting. I really have no clue why some of the content was slightly off - but it made editing the existing content more challenging.

I also was spending more time upgrading Drupal (fixes for different modules and security patches for modules and Drupal itself) then I was creating content or doing work or research. It wasn't a lot of time, but it did take time for me.

None of this is to blame Drupal. This is just an explanation for two of the reasons I decided to leave Drupal. And these may be MY issues, and not problems with Drupal as I altered the modules, configuration, and content over time. There was also a third reason I chose to migrate away from Drupal....I had started monitoring my website for outages which provided the added benefit of giving me page load times. My web server also ran a SMTP relay and a database server, so I was not looking for huge performance, but I discovered that my website was taking up to 1.5 seconds (and sometimes longer) to load.

While looking at alternatives I discovered that converting to a static website would significantly reduce the load time for my content. (In simple terms, loading straight HTML would be faster to load than dynamically generating content from a database and formatting it on the fly.)

All these things really combined together, at a really good time, for me to make a migration away from Drupal and to a static site generator. And that will be another blog post.

Convert VMWare to KVM

I used to run vmware (specifically VMWare Workstation), but I had to move away from it for a variety of reasons. It was fairly stable (I did run into a few issues, but always found a way around them after some work), so that wasn't the reason. (For those who care, every time I received a new kernel under Linux, I would have to recompile some modules and load them into VMWare and I just got tired of the hassle of doing that).

So I wanted to move almost a dozen vmware machines to another Virtualization stack. I looked at both VKM and Virtual Box and settled on KVM. I found some basic instructions on the KVM website here (http://www.linux-kvm.org/page/How_To_Migrate_From_Vmware_To_KVM) but they are so cryptic, I had trouble following them!

So this is an attempt to remedy that problem.

Read more…

netcat

File transfer

Most of the time we are trying to transfer file over network and stumble upon the problem which tool to use. There are again numerous methods available like FTP, SCP, SMB etc. But is it really worth the effort to install and configure such complicated software and create a sever at your machine when you only need to transfer one file and only once.

Suppose you want to transfer a file “file.txt” from A to B

Anyone can be server or client, lets make A as server and B as client.

Server

$ nc -l 1567 < file.txt

Client

$ nc -n 172.31.100.7 1567 > file.txt

Here we have created a server at A at redirected the netcat input from file file.txt, So when any connection is successfull the netcat send the content of the file.

Again at the client we have redirect the output of netcat to file.txt. When B connects to A , A sends the file content and B save that content to file file.txt.

It is not necessary do create the source of file as server we can work in the eopposeit order also. Like in the below case we are sending file from B to A but server is created at A. This time we only need to redirect ouput of netcat at to file and input at B from file.

B as server (Server)

$ nc -l 1567 > file.txt

Client

$ nc 172.31.100.23 1567 < file.txt

Reference: http://mylinuxbook.com/linux-netcat-command/

Presentation on collectd / Graphite for PLUG

Below is my presentation from April for the Portland Linux/Unix Group (PLUG) Computer Group Advanced Topics Meeting. I wish I could thank the second person who jumped in and help answer some of the questions that I didn't have answers to.

There is a Version 1.0 (my draft), as well as a Version 1.1 (what I presented from) LibreOffice Presentation attached. Please contact me if you have any questions. I'm hoping to add some more Articles on this website when time allows (when does it ever?).

[http://www.tbruce.com/PLUG%20-%20Monitoring%20Presentation%20v1.0.odp] [http://www.tbruce.com/PLUG%20-%20Monitoring%20Presentation%20v1.1.odp]

  • These files need to be moved into a subdirectory. *

PostgreSQL Sequences and Drupal

I was using Drupal and after one of my upgrades, something changed in the database (I wish I'd taken better notes of which upgrade and saved a copy of my backup, but I didn't do that quick enough so I've lost the data). In any case, my database sequences no longer matched up with what the database was expecting.

In fact, I was getting the following error:

* warning: pg_query(): Query failed: ERROR: duplicate key value violates unique constraint “node_revisions_pkey” in /path/to/drupal-6.2/includes/database.pgsql.inc on line 139.
* user warning: query: INSERT INTO node_revisions (nid, uid, title, body, teaser, log, timestamp, format) VALUES (0, 1, ‘test’, ‘test test test test test test test test test test test vv’, ‘test test test test test test test test test test test test test vv’, ”, 1294612270, 4) in /path/to/drupal-6.2/includes/common.inc on line 3538.

All my research led me to believe that it was an issue with my sequence not being bound to my column correctly. However, I could see through psql that my column in the table was bound correctly. Finally, tired of debugging on and off over several months, I turned full logging onto my database and saw another error (now, if I'd really looked at the message, I might not have had to do that as I was able to get a clue from this web site: http://www.devissues.com/tag/drupal)

By looking at the sequences and the tables (with the following commands), I discovered that my sequence was reset to a lower value.

tim=# SELECT nextval('node_nid_seq');
 nextval
---------
     150
(1 row)

tim=# SELECT max(nid) FROM node;
 max
-----
 149
(1 row)

tim=# SELECT nextval('node_revisions_vid_seq');
 nextval
---------
     109
(1 row)

tim=# SELECT max(vid) FROM node_revisions;
 max
-----
 144
(1 row)

Looking at the sequence for node_devisions_vid_seq and lookign at the max number of the vid from node_revisions...hey, I've got a mis-match. Resetting the sequence to be 146 solved my problem. Here is the actual SQL:

tim=# ALTER SEQUENCE node_revisions_vid_seq RESTART WITH 146;

And that seems to have fixed my problem for the database.

Change Table Ownership in PostgreSQL

I wanted to fix a problem with all the tables that were owned by a specific user. I looked up the user and found out it was a user with the ID (OID) of 16387.

Then I could use the following command to generate sql to fix the ownership in my database.

select 'ALTER TABLE ' || relname || ' OWNER TO web_user;' from pg_class where relkind = 'r' and relowner = 16387 order by relname;

This generated the following SQL for me (some people might recognize this as a way to generate dynamic SQL):

ALTER TABLE access OWNER TO web_user;
ALTER TABLE accesslog OWNER TO web_user;
ALTER TABLE actions OWNER TO web_user;
...
ALTER TABLE vocabulary OWNER TO web_user;
ALTER TABLE vocabulary_node_types OWNER TO web_user;
ALTER TABLE watchdog OWNER TO web_user;
ALTER TABLE webfm_attach OWNER TO web_user;
ALTER TABLE webfm_file OWNER TO web_user;
ALTER TABLE wysiwyg OWNER TO web_user;
ALTER TABLE wysiwyg_web_user OWNER TO web_user;

I could then run this output in my Postgresql client (psql as one example) to apply these ownership changes to all the tables (notice that my list above is NOT complete). (Just don't forget to be connected to the correct database or it will fail with a message like: ERROR:  relation "url_alias" does not exist.)

Fix Editing a Drupal Web Page

I had another recent challenge with Drupal (again, some other upgrade or change to my web server / database server) where I was no longer able to edit a page after loggging into my Drupal website.

Since I was using PostgreSQL I was able to update a few specific fields in a couple tables when I could no longer update my content on a particular page (node 145). I used pgadmin3 to run this query.

You need to update two different tables to fix the problem with unable to edit a page. Both the node and node_revisions tables need to be updated.

Then run the following code to update the page:

This allowed me to fix it so I could now EDIT the page inside Drupal.

NOTE: This worked for me with Drupal 7. This may not work for you. And any changes you make directly in the database could have other impacts. Validate your data and how Drupal is working (tracing queries, etc) before you directly make changes to your backend database.

Fonts in Linux

Fonts are important. With different fonts you can emphasize text or just give your text a little pizzazz. Or you could simply make it more readable to your own eyes (which of course is a subjective measure). Many people don't change fonts, but instead change it using italics or bold or change the size (usually measured in points or 72nds of an inch).

There are several different commands to list the fonts available on Linux.

$ fc-list

is one way to list fonts. This will list all the vector based fonts (True Type Fonts or TTF and Adbobe Type 1 Fonts or PBF). There may be other types of Vector fonts installed. Another is:

$ xlsfonts

One thing you may want to do is sort the list or run it through grep to filter out some things, especially since there is no specific order for the fonts to be returned in.

This page might also help: http://crunchbanglinux.org/wiki/urxvt

For many of my consoles (terminal sessions) like xterm, I like to use mono-spaced raster-based fonts. These are some additional fonts I was looking at with xterm:

timb@tardis:~$ xterm -fn r14
timb@tardis:~$ xterm -fn r24
timb@tardis:~$ xterm -fn 12x24
timb@tardis:~$ xterm -fn 10x20
timb@tardis:~$ xterm -fn 5x8
timb@tardis:~$ xterm -fn -rfx-courier-bold-o-normal--0-0-0-0-m-0-microsoft-cp1251

Fonts on Krycek (from xtermfonts didiwiki page)

Some of the fonts I can use:

Various Fonts

xterm -fn '-adobe-courier-medium-r-normal--0-0-0-0-p-0-iso8859-2'
xterm -fn '-bitstream-courier 10 pitch-medium-r-normal--0-0-0-0-m-0-ascii-0'
xterm -fn '-bitstream-courier 10 pitch-medium-r-normal--0-0-0-0-m-0-iso8859-1'
xterm -fn '-misc-fixed-bold-r-normal--0-0-100-100-c-0-iso8859-1'
xterm -fn '-misc-fixed-bold-r-normal--0-0-75-75-c-0-iso8859-1'
xterm -fn '-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso10646-1'
xterm -fn '-misc-fixed-medium-r-normal--15-120-100-100-c-90-iso8859-1'
xterm -fn '-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso8859-1'
xterm -fn '-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-1'

xterm -fn '-misc-fixed-medium-r-semicondensed--12-110-75-75-c-60-iso8859-1'
xterm -fn '-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1'

xterm -fn '-schumacher-clean-medium-r-normal--0-0-75-75-c-0-iso8859-1'
xterm -fn '-schumacher-clean-medium-r-normal--12-120-75-75-c-60-iso8859-1'

Standard Fixed

xterm -fn '7x13'
xterm -fn '8x13'
xterm -fn '8x16'
xterm -fn '9x15'
xterm -fn 'a14'

Misc Fixed

xterm -fa MiscFixed -fs 8
xterm -fa MiscFixed -fs 10
xterm -fa MiscFixed -fs 12

Fixed

xterm -fa fixed -fs 8
xterm -fa fixed -fs 9

xterm -fa fixed -fs 10

xterm -fa fixed -fs 12