Categories
Command Line (CLI) Distributions Web Development

What *Nix distro now?

Hi all, long time no write.
The time has come, well, it’s always been here I suppose… that lingering feeling that the distro you’re using is in need of replacement.
I’ve been using Ubuntu Mate for years now, and it’s great. No complaints with it, the issue is one that is known to many of us trying to get as much horsepower as possible from an old laptop.
How old you ask? Well it’s from 2009, and is an HP G60 in very good shape. Over the years I have maxed out the RAM, replaced the spinning disc HD with a Solid State Drive, and have replaced the keyboard and the battery. I’m just trying to get best performance out of it while trying to solve a few other problems/challenges in the process.
So glad you’re still reading this!! OK. Recently at work they have enabled Host Checker on the company’s VPN login stage. This basically means that my previous implementation of a 64-bit OS with some additional 32-bit java libraries added in (from mad-scientist directions) is no longer working. This used to work, and now it does not. Host checker fails because it can’t find program to run java applets or find an Antivirus program.

Isn’t that a kicker? Linux, a more secure operation system (in general) than Microsoft Windows…. is not considered “secure enough”…

I’ve been trying a few things to get it working within the scope of “host checker” and found this Perl script called jvpn but it isn’t working. I’ve done all I can within my own coder skill set to try and root out code issue or lack of java library issue, but there simply are no foolproof ways to make it work, and I feel this approach is simply very very hackish.

I was considering using an older 32-bit OS as an alternative, but in this day and age, that feels like going too far backwards in time. 32 bit?
The promising concepts of 32-bit:

  • The Java libraries will be 32-bit from day 1
  • I can install Java-enabled ESR release of Firefox

I’ve also read that FreeBSD is capable of establishing this connection to Juniper VPN, but I’m not convinced. For a week I tried out installing FreeBSD, and then installing TrueOS on top of it for a graphical environment. I may have done something wrong in that the machine felt slower in performance and the desktop (Lumina environment) just seemed to lack polish and if it’s going to be slow, at least it should look better in my opinion.

Does anyone have an idea on how to properly connect a Linux/BSD computer to a Juniper VPN with host checker enabled? Feel free to leave a comment. Thanks.

Categories
Applications Command Line (CLI) Using Linux

Burning Music CD Backup is not simple

Recently, I needed to backup a Music CD with my Linux OS.  Sadly, this was not simple.  This post discusses using Linux to back up a music cd. Nothing more, nothing less. I don’t intend to promote or sell my backups.  Yes, I am aware that

  • On Mac and Windows, music cd backup woes aren’t worth discussing since easily-obtainable programs exist
  • This is an area of computer use that can raise eyebrows

Why backup our music CDs?

Safekeeping in a familiar location; your personal computer

If I backed up my Led Zeppelin CD “In Through the Out Door”, then I wouldn’t be upset about it (it’s missing). Of course, music CDs are not as expensive as they were before the days of digital purchase, digital download, and youtube, but it’s the principal of it.

Easily encode & transfer music for different formats & players

For example, you make a digital backup of “In Through the Out Door”. Your wife wants to listen to it on her iPad in high quality audio format.  Your nephew would also like to listen to it, but has limited audio file type support and less storage space on his iPod Touch.  With a full digital backup of the cd, you can easily encode the songs to satisfy both requirements without having to take the original music cd out of its case multiple times.

You covered “why”, ? “how”

I will first give citation to the source of the solution that worked for me. See the first post from user noz in How to dump an Audio CD to ISO from the freebsd forums for the instructions. I found a “gotcha” (possibly) overlooked in the “Playing it” section;  Note: Playing the BIN without conversion will give you an earful of static.  This is notable, it also applies to the burn process.  You want to burn the converted (not original) bin file.  I got this wrong the first time. To avoid the mistake the 2nd time, I did the following:

  • Kept the file names the same for both original and converted bin files.
  • Used sed to replace the source (in TOC) to the converted bin file. Sed was quicker than a GUI text editor to accomplish same [find/replace] task.

For example, if your original bin = in-out-door.bin, converted bin = in-out-door-converted.bin, and TOC file is in-out-door.toc

sed -i -e ‘s/in-out-door.bin/in-out-door-converted.bin/’ in-out-door.toc

You might prefer to rename the .bin files and leave the toc as-is. It’s up to you.

Categories
Command Line (CLI) Learning Linux Using Linux

Untar Several Files to a directory

Today we’re going to talk about the UNIX tar command.

Specifically, how to use tar to extract or unpack several archives (tar.gz files).  Only – instead of extracting them to the same directory, we’re going to extract them to a named directory.

This utility came in handy after downloading close to 10 gkrellm themes from http://www.muhri.net . I have used the Gkrellm Monitoring tool over the years and was always disappointed with the (somewhat) `boring` stock themes.  I mean, if you’re going to have something sitting on your desktop, using resources to report on resources, then why not have it look slick, sick, or at the very least—”easy on the eyes”… right?

Why would anyone want to unpack tar.gz files with the command line in Linux when there are GUI tools available?

Right, the linux OS comes packed with tons of GUIs to handle files and archives.  We have programs such as FileRoller.  I have used it but imagine you have downloaded (oh I don’t know, twelve) archives that are themes for gkrellm.  Would you really want to use the manual effort of unpacking all of them first, directing the GUI (with more clicks) where to save the extracted files to?

What if I told you that you can accomplish the same in the Linux Shell with a basic loop over a set of tar.gz files?  You’d probably want to take the quick way I bet.  I know I did.

Ok, get on to it already.  Right. Here we go.  Firstly, I’d be a bad dude if I didn’t at least name some links that I googled along the way to building the handy-dandy loop I’m about to share with ye.  http://lejalgenes.com/ very simple layout, 2 commands that do the trick.  And http://www.linuxquestions.org/ which has the command, and provides advice too.

Using the basic concept of the command, which unpacks a tar.gz to a named directory:

tar -zxvf tarball.tar.gz -C <directory>

Then, using a loop construct, where the find command provides a list of tar.gz files, we iterate over the list, unpacking each one to the specified directory following the -C.

The setup:

  1. Have all of your (downloaded) tar.gz files in the same directory.  You may want to get rid of archives that are unrelated to gkrellm themes.
  2. CD to that directory.  We will extract to the .gkrellm2/themes.
for fyl in $(find . -type f -name "*gz");\
do tar -zxvf $fyl -C /home/awsmeadam/.gkrellm2/themes; done

And that’s it.  Done.  Did you download more tar.gz themes?  Ok, run the command again.

If I run the command again, the previously-unpacked files will get over-written, won’t they?

Yes, they will.  In most cases, this is bad.  But since this is a theme unpack, you really have little to worry about unless you’ve edited or otherwise customized a theme.

Enjoy, and happy Linux-ing.

 

 

 

Categories
Applications Command Line (CLI)

cygwin error loading shared libraries

If you’ve been using Cygwin for a while, particularly imageMagick functions such as convert, you may notice some breakages on updating your cygwin version.  Errors such as:

convert: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

– it’s (Cygwin) telling you that there are some libraries missing.  You’ll need to find out which ones and then run the setup/installer to fix it.

To Fix it, first use the cygwin utility ‘cygcheck’ to reveal the names of the missing DLLs.   Since this post references the convert function of imageMagick,  run the command:

cygcheck convert

to generate a list of the missing libraries/DLLs.  For more information, you can check cygwin’s documentation site.  If you’re having trouble with “montage” : then in cygwin run:

cygcheck montage

and it should list out for you the libraries that it cannot find, one such library had the word “gomp” in it.  In the cygwin setup/installer, you’ll find the library just by putting in the last few letters (gomp) should find a match for you (or at least close enough) and click the checkbox to install the library.  Another missing library was TIFF- related.

In my case, it was missing the exact same libraries as cygcheck convert.  Once the install was complete, then the ‘convert’ function was back and running as expected.

HOO-RAY!!!

Categories
Command Line (CLI) Using Linux

Cygwin rename command help

Rename files in cygwin, overcoming a limitation

Cygwin is a Linux-like environment for Windows.  It comes in handy when you’re at work, or at home, and your only operating system happens to be Microsoft Windows.  Cygwin allows you to issue Linux commands in a console in Microsoft Windows.  I find it easier to use than the DOS CMD prompt when I’m using a Windows OS.  It’s a great way to get things done quicker, and can be scripted—in a similar environment to a Linux Terminal.

So, let’s say you’re seasoned in the Linux shell.  You’re now at work, using Cygwin, and you want to rename a lot of files based on their name matching a pattern of letters or numbers or both.  This is where cygwin has some trouble.

By default, cygwin does not come with rename ability.  The package util-linux is required.

Cygwin’s rename command renames files if you tell it the exact name of your target file.  This is the same as the mv command. I’m no Cygwin expert, but this is the experience I’ve had.

In Linux, you can rename files using wildcards or pattern matches.  Cygwin’s rename command cannot seem to handle regexes in the same way.  I’ve tried a fair amount of googling to see why this command has limited behavior in cygwin.  I haven’t found a usable solution or add-on to cygwin to overcome this limitation.

So, here’s a shell script that uses sed, mv, and find to overcome the limitation.  I was unable to attach it, so I copied and pasted it below.

Please understand and accept the following disclaimer:  YOU MAY USE & MODIFY THE SCRIPT.  AUTHOR ASSUMES ZERO LIABILITY.  SCRIPT INTENDED FOR USE IN CYGWIN WITHIN A WINDOWS OS. SCRIPT COMES WITH NO WARRANTY, USE AT YOUR OWN RISK. Thanks.

#!/bin/sh
# cygrename : A Program to overcome limitation of cygwin's "rename" function.
# Author: Adam Teller
#
# Cygwin's "rename" doesn't work same way as *Nix "rename"
# because it cannot use wildcards. So, what can we do?
## Get the basename of the file if it matches search pattern.
## If 4th argument is set, change file to that suffix.
## else, match pattern within file name and keep same suffix
#
## Arguments: [search pattern] [replace pattern] [in suffix] [to new suffix]

LIST1=$(find . -type f -name "*${1}*\.${3}")
if [ -z "${LIST1}" ];
 then
   printf "Did not find any file matches, program will exit\n"
 exit 1
fi

for found in $LIST1;
 do
   MATCHEDFILE=$(basename $found);
   NEWFILENAME=$(echo $MATCHEDFILE | sed -e "s/${1}/${2}/");
   NEWFILENAMENOEXTENSION=$(echo $NEWFILENAME | sed -r "s/\.${3}//");

   ## TEST if $4 has been set, it means want a new file suffix
   if [ -z "${4}" ];
     then
       printf "$MATCHEDFILE :to be renamed as: $NEWFILENAME for files of type ${3}\n";
       mv $MATCHEDFILE $NEWFILENAME;
     else
       printf "${NEWFILENAMENOEXTENSION}.${3} will get $4 as its suffix, ";
       printf "and be renamed to ${NEWFILENAMENOEXTENSION}.${4} \n";
       mv $MATCHEDFILE "${NEWFILENAMENOEXTENSION}.${4}"
  fi
 done

 exit 0

Ok, I’ve copied the script and saved it, how do I use it?

  • Run your script from the same directory that has the files that you want to rename. I’ve named my copy “cygrename” (short for “cygwin rename”) but you may save your file with another name if you wish.  Make sure your script is executable. Use the cd command to get to the correct directory.
  • It accepts 3 or 4 command line arguments.
  • Invoke it in the shell using sh cygrename “what-to-find” “replace-it-with” “file extension” “new file extension” (optional).
  • The “file extension” argument does not include the dot (.), just use letters such as txt or doc or gif.
  • 3 arguments is the minimum and I’ve omitted the argument counting, you may however wish to add it into your program so that the 3 argument minimum is enforced.
  • In the even that the program does not find a match, the program exits.
  • The script uses the find command to look for files matching your pattern.  The result of a “find” usually includes the path information.  This is why we use the basename directive.  We just want the actual file name.  For example, a call to find might result in “./file1.pdf” and what we really want to use is “file1.pdf”
  • If the optional 4th argument is used, it indicates a desire to change the file suffix.  Otherwise, you can rename files and keep the file suffix as is.

Here’s a way to store & use the script.  This script is yours to use & modify as you wish.

  1. Store the script (assuming you’ve named it cygrename) in the “bin” folder in your user’s home folder.  In a windows environment, this is usually C:\cygwin\home\userName\bin.  When you first see this folder, it should be empty.  There is a cygwin “system” bin that will be full of executable files. THIS IS NOT what you’re looking for. You are looking for your user’s bin folder, which will be empty until you start putting files into it.
  2. Once you’ve used the cd command to get to the folder where the target files reside, you can invoke the script.  The script can be more easily invoked if you change the PATH variable in Cygwin.  Find instructions here.  Adding your user’s bin directory to your search PATH is recommended because it will allow you to call the script just by its filename, and won’t require the entire path name of the script.
  3. In this example, for simplicity, I’m assuming you have several files in the same “bin” directory as the script you have saved.  You have 4 image files named “picture1.jpg” “picture2.jpg” “picture3.jpg” and “picture4.jpg” .  You want to change “picture” to “img” and keep the files as *jpg  -From within the “bin”directory, Call the script as sh cygrename “picture” “img” “jpg”
  4. Your 4 jpg files should now be named “img1.jpg”, “img2.jpg” and etc.
  5. If (based on previous example) you wanted to change some web files (html) AND their file suffix, you could call the script as sh cygrename “website” “site” “htm” “html” and it would rename files such as “websiteLocation.htm” to “siteLocation.html” because you used the optional 4th argument.
  6. Please be aware that simply changing a file extension DOES NOT CONVERT a file.  What I mean is that if you change a file suffix of “img2.jpg” to “img2.gif” you are not converting to the gif file type.  The file becomes a jpg file named with an incorrect suffix.  This is not recommended.  However, changing an extension from .htm to .html is ok because it is a text-based file.  Image files, office suite files, and multimedia files should only have their suffix changed by using another application to convert the files.
Categories
Command Line (CLI) Learning Linux Using Linux

Using Linux at Work

Use Linux at work—even if your PC runs Windows.

When I started using Linux, I wondered when I would get to actually use it “on the job”.  It wasn’t easy sometimes to work with a Windows-based computer—when there’s a skill set available that can help you do things faster on the computer.  This skill set is the Linux command shell, but as mentioned your computer runs Microsoft Windows.  What can you do??

At one job, I was able to install Perl.  At another job one had to submit a request (with business justification) to add software to a workstation.  Instead of Perl I thought “why not Python?”  Since both times it was a Windows XP Environment, I used the DOS command line (or “CMD” app) to execute the Perl or Python programs.

I used the DOS CMD because (at that time) I did not know about Cygwin.  Using the DOS CMD to execute programs is easy.  The difficult part is dealing with case-insensitivity (which hurts portability) and using a shell to navigate folders with spaces in the names is a real pain.

Using the DOS shell to execute programs is not the same as using Cygwin.  Cygwin is command shell that emulates a working Linux environment.  Installing Cygwin with the base packages is simple and will provide a good “starting point” for learning some shell commands.

Want to use Linux but your work computer is Mac OS-X?

OS-X (like Linux) is Unix-based.  It has a shell that’s known as “Terminal” and it is in the Applications/Utilities folder.  You can also (if the OS is 10.5 or later) use keystrokes (apple + Space bar) to show the “spotlight search” box at the top right and start typing Terminal.  When search finds “Terminal” then press ENTER and voila!  Say hello to the Darwin Terminal.

Darwin handles the basic stuff really well.  It’s capable of helping you learn Shell commands.  But it doesn’t do everything that a regular Linux distro does.  Darwin’s limits can be overcome by installing apps and libraries.  Most likely you will need your System Administrator’s help to get and install X11, MacPorts, or Fink to augment the BSD-derived Darwin environment.

Categories
Applications Command Line (CLI) Introduction Your Choice

Favorite CLI Linux Apps: Intro

We’re talking about the Linux command line…again.  Don’t worry, I won’t bore you (hopefully). If you’re still on this page, I commend you.

Remember, a Linux user should never feel forced to use the terminal or “console”, but knowing how to use it will help you get the most out of Linux.  The speed, simplicity, and the consistency are what drive me to use it nearly every time I’m at a Linux Desktop.

Ok, here’s a list of programs that are typically not in a distro by default.  These programs are intentionally run from a terminal prompt.

Categories
Applications Command Line (CLI) Your Choice

Favorite Linux CLI Apps: Emacs

Emacs text editor (also known as emacs21-nox*)

[*The GNU Emacs editor without X support] is not usually part of a distro install—but it should be.  When you need to quickly edit a text or config file, a shell command can open the file, let you save changes, and then return you to the shell prompt.  Default console-based text editors (pre installed) are vi or nano.  I’ve tried them both.  I like emacs better.  At the time of writing, Synaptic in Crunchbang Linux 9.04 shows the console emacs as “emacs21-nox”

There are split camps and heavy debates as to which is better.  Just google  “vi vs emacs”.  It is useless for me to jump on the debate bandwagon.  Just know that they are similar, but operate differently.  Both edit and save text in a console/terminal.  Both offer no formatting or styling like a GUI word processor.  However, vi is a “modal editor” meaning that you switch back and forth between “insert mode” (for typing) and “command mode” (to issue file, search, or text-related commands.  Emacs is all one mode, where keystroke combos invoke commands.

Forget the evangelism or the “he said/she said bull$h1t”.  Try them both and see what you like.  You can always uninstall an unwanted application program with Synaptic.

Categories
Applications Command Line (CLI) Web Development

Favorite CLI Linux Apps: php5cli

php5cli runs PHP commands in a shell

PHP is a scripting language used on many websites.  It allows a page to do “dynamic” things (such as changing a page’s appearance based on user input, time or date, etc.)

One of the things I do wtih php5cli (or php in the shell) is check a PHP script for errors.  This saves you the trouble of running your PHP-based web page in a browser (which may have bad side effects).  ??Bad side effects?? Sure, what if your page is supposed to overwrite a file, and then hits an error.  It may erase a perfectly-good file.  Ok, enough gloom and doom talk.  Let’s say you wanted to check “myPHPscript.php” for errors. Run the following command in a shell to check it for errors before it runs/executes.  The option is a lowercase L (l) not a digit.

php -l myPHPscript.php

Another good use of PHP in a terminal is to generate HTML code.  There’s a certain frustration in coding up an entire web site, and then needing to go back and make a change across all your pages.  A time (and headache) saver is to let PHP do the “heavy lifting” for you.  What does this mean?

Basically, you set up a series of instructions for a script to follow.  Then, based on your needs, you make the script “write” different output based on a variable whose value may change.  Sometimes this involves changing the size of table cells, but it could apply to writing an entire series of web pages.  It comes in way handy when you’re looping over database results (and deciding to print the 2nd line of an address to the page).

In summary, when you’d have to change the same attribute in many, many places, and change them a few times, manually finding the attribute (for example a web link), you don’t have to manually (not mention “tediously”) hunt for the item(s) you want to change.  Install php5cli with Synaptic (or other) package manager. This installs any needed dependencies.

Categories
Command Line (CLI) Your Choice

Favorite CLI Apps: Imagemagick

Imagemagick

Imagemagick is an awesome command-line based image manipulation tool.

[Paraphrased from the imagemagick manual:]

ImageMagick®, is a software suite to create, edit, and compose bitmap images. It can  read,  convert  and  write  images in a variety of formats. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform  images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bezier curves.  ImageMagick  includes a number of command-line utilities for manipulating images. Most of you are probably accustom to editing images one at a time with a graphical user interface (GUI) with such programs  as gimp or Photoshop. However, a GUI is not always convenient. Suppose you want to process an image dynamically or you want to apply  the  same  operations  to  many images  or  repeat  a  specific  operation at different times to the same or different image. For these types of operations, the command-line image processing utility is appropriate.

To install imagemagick, use Synaptic, or issue the following command in a terminal

sudo aptitude install imagemagick

Visit my post on using Imagemagick to perform the same process on multiple images.

There are many examples on the imagemagick website.