// Internet Duct Tape

Removing filenames starting with – under Unix

Posted in Asides, Linux and Unix, Technology by engtech on July 11, 2006

One problem users sometimes hit under Unix is how to remove files that start with the “-” character since it usually implies an option to the remove command.

The secret is to use “–” to signify that all further options are to be ignored.

rm -- -bad_filename

Comments Off on Removing filenames starting with – under Unix

Linux and Unix tutorials // Tille’s Homepage

Posted in Links, Linux and Unix, Technology by engtech on May 28, 2006

There are several tutorials at this site:

Tille's Homepage

Comments Off on Linux and Unix tutorials // Tille’s Homepage

Differing features between sh, ksh and csh (if, for, loops)

Posted in Links, Linux and Unix, Programming and Software Development, Technology by engtech on May 28, 2006

The table at this link shows the differences between sh, ksh and csh and can be a life saver when you are trying to remember the exact syntax differences when going from one to the next.

 Differing features

Comments Off on Differing features between sh, ksh and csh (if, for, loops)

Improve Your Scripting with the test Command

Posted in Links, Linux and Unix, Programming and Software Development, Technology by engtech on May 28, 2006

'test' is easily the most important command to know how to use when writing shell scripts. This is a really good tutorial that gives a full list of all supported commands and various Bourne shell examples.

The shortest-possible definition of the test command is that it appraises an expression and, if its condition is true, returns a 0 value. If the expression is not true, it returns a value greater than 0—which can also be said to be a false value. The easiest method of checking the status of the last command performed is via the $? value, and examples throughout this article use that parameter for purposes of illustration.The test command expects to find an argument on its command line, and when the shell has no value for a variable, the variable is considered null. This means that if a script is being processed, test reports the error whenever the script looks for an argument and does not find one.

When attempting to bulletproof scripts, you can solve this problem by enclosing all arguments within double quotes. The shell then expands the variables and, if no value exists, passes a null value to test. Another option is to add an extra check procedure within the script to see if the command-line arguments have been set. If not, the script can tell users that arguments are needed and then exit. All of this will make more sense as we work through some examples.

Improve Your Scripting with the test Command

Comments Off on Improve Your Scripting with the test Command

icewm

Posted in Links, Linux and Unix, Technology by engtech on May 28, 2006

Ice Window Manager is a linux window manager built with "speed, simplicity, and not getting in the user's way" as the foremost goals. It's really good for when you want a low memory window manager (ie: running linux under VM-Ware).

icewm

Comments Off on icewm

Don’t beep at me — turning off the console beep in unix shells (xterm)

Posted in Asides, Linux and Unix, Technology by engtech on May 28, 2006

This page on unix system administration has some quick tips on how to turn console beeps off under a variety of settings (console, xterm, different shells)

In a plain linux console (no graphical X11) you can turn the beep off with the command:

setterm -blength 0

When working under X11 (no matter if KDE, Gnome, XFCE, or … is used) you turn off the beep with:xset b off

lf378, SystemAdministration: LF Tip: Don't beep at me

Comments Off on Don’t beep at me — turning off the console beep in unix shells (xterm)

How to embed single quotes in a tcsh alias

Posted in Asides, Linux and Unix, Technology by engtech on May 25, 2006

When writing aliases there is a mechanism for including single quotes within the alias.

alias test 'echo put some single quotes here '"'"'this is quote"'"'" there were quotes'

This makes is useful for creating one line perl aliases. The following aliases could have probably been done more tersely with sed, but this format will be easier to understand if you're familiar with perl.

# Returns the current directory in my user account.
alias myd 'perl -w -e '"'"'use strict; use Cwd;   my $home = "/home/";   my $pwd = cwd() . "/";   $pwd =~ s/$home.*?\//$home$ENV{USER}\//;   print $pwd;'"'"''
# Returns the current directory on another user account.
alias otherd 'perl -w -e '"'"'use strict; use Cwd;   my $other_user = $ARGV[0];  (defined $other_user) || die "alias otherd: specify a user account!";  my $home = "/home/";   my $pwd = cwd() . "/";   $pwd =~ s/$home.*?\//$home$other_user\//;   print $pwd;'"'"''
# These aliases assume an option called e that launch a text editor. 

# Open the same file under my directory.
alias myf 'e `myd`\!*'
# Open the same file under someone else's directory.
alias otherf 'e "`otherd \!:1`\!:2"'

Comments Off on How to embed single quotes in a tcsh alias

Virtual Appliances and VM-Ware

Posted in Asides, Linux and Unix, Technology by engtech on May 23, 2006

This is old news, but if you want to easily run Linux/OpenBSD simultaneously with Windows you can use a free VM-Ware client along with an image of that OS (called a Virtual Appliance). The key differentiator to look for is that they have VM Tools installed since it will reduce some of the headaches of switching back and forth between your Virtual Appliance and Windows.

This is a better solution than installing Cygwin, ActiveState Perl, Xemacs, etc on your Windows machine (like I have at home).
Virtual Appliances: VMTN Appliances

symbolic link checker in Perl and script to find biggest files

Posted in Links, Linux and Unix, Perl, Technology by engtech on April 27, 2006

These are a couple of perl utilities I've found useful.

linkcheck.pl is for finding broken symbolic links. biggest.sh is for finding the largest file on a file system (ie: when you've run out of diskspace and you need to find the culprit)

linkcheck.pl looks for all links on the local file system and tests each link's integrity–to determine whether the link still valid, or if it points to an object that no longer exists. Only local filesystems are searched and this is ensured by testing each filesystem argument via "df -l" command.

Listing broken links is helpful, and you can certainly write a much shorter Perl program to do that, but linkcheck.pl comes with other useful options:

    -a Display All links
    -H Detailed documentation
    -h Usage brief
    -l Long list (e.g., ls -al)
    -r Remove broken links (use with caution)
    -v Verbose output
    fs Required filesystem for search (multiple filesystems may be specified)

How many times has a file system filled up causing you to spend more time than you liked finding that hernia file or files? I'll wager more times than you care to remember. After I lived with that aggravation for way too long, I put together biggest.sh.

Biggest.sh has run successfully on Sun Solaris and Linux. It is written in Bourne shell (instead of Korn or Bash) for one reason only – portability. The script runs under Bourne, Korn, and Bash environments without modification.

   Usage: biggest.sh -fHh -l <nn> -v -t <dir> -s <nnn> fs     -f - Follow links
     -H - Displays detailed documentation
     -h - Provides usage brief
     -l - Displays <nn> lines (default is 500)
     -s - Minimum file size is <nnn> (default is 500K)
     -t - Use <dir> as temp/work directory (default is /var/tmp)
     -v - Edit (vi) file list
     fs - Required file system argument

Bob Orlando's Unix Tools

Comments Off on symbolic link checker in Perl and script to find biggest files

Linux family tree

Posted in Links, Linux and Unix, Technology by engtech on April 25, 2006

The various linux distributions and how they are related to each other.

GNULinuxupdatedw4.0.jpg (JPEG Image, 1024×849 pixels)

MySql – Backup and Restore of MySql database with phpMyAdmin

Posted in Links, Linux and Unix, Technology by engtech on April 20, 2006

Backup and Restore of MySql database with phpMyAdmin

It's recommended to use the shell commands because of database size issues, but sometimes that isn't possible.

Comments Off on MySql – Backup and Restore of MySql database with phpMyAdmin

MySQL 5.0 Reference Manual :: 2.4 Installing MySQL on Linux

Posted in Links, Linux and Unix, Technology by engtech on April 20, 2006

MySQL 5.0 Reference Manual :: 2.4 Installing MySQL on Linux

This is a more indepth guide to installing MySQL on Linux that goes into detail explaining the various RPM packages, possible error conditions. It also has a user comment thread that contains further corner cases.

Comments Off on MySQL 5.0 Reference Manual :: 2.4 Installing MySQL on Linux

Installing/Using MySQL on RedHat Linux – very high level tutorial

Posted in Links, Linux and Unix, Technology by engtech on April 20, 2006

Installing/Using MySQL on RedHat Linux

This is a very high level tutorial about how to install MySQL on RedHat Linux. Author assumes that user is completely unfamiliar with databases/SQL.

In a nutshell:

  • download the RPMs from http://www.mysql.com
  • install using 'rpm –install'
  • set root password for mysql

What is of interest is the section on how to secure the MySQL server:

  • When you create an account, give it a password.
  • Create a separate account for each function for each database and restrict rights appropriately.
  • Only allow database access from "localhost."
  • Do not enter the password on the command line (-p[password]) if you are on a multi-user system because other people could see it if they use the `w` or similar commands.
  • Remove any unused or seldom used databases (like the "test" database which is installed by default).

How to find out which version of Linux you are running

Posted in Asides, Linux and Unix, Technology by engtech on April 20, 2006

Differ distros will give different results, but they are usually under /etc/*-release
Red Hat uses /etc/redhat-release

> cat /etc/redhat-release
Red Hat Enterprise Linux WS release 3 (Taroon Update 6)