Skip to main content

Linux Command Line Loops

There are times you want to enter a single-line command to unzip all the files in a directory. If the current directory is:

/home/timb/download/files

the command would be:

for i in `ls ~/download/files/`; do tar -xzvf ~/download/files/$i; done

This would unzip every .tar.gz file in that directory into your current directory.

Proxy in Linux

There are times when you need to route all your web traffic (http) and file transfer (ftp) traffic through a proxy. This may be because you're in a business environment and all traffic is "inspected" prior to going to the destination site or it may be at home where you've installed proxy software to monitor the kids or block them from some web sites / ftp sites.

Setting up the information in Linux to use the proxy is as simple as adding the following lines in one of several files.

export HTTP_PROXY="http://192.168.0.2:8118/"

export FTP_PROXY="http://192.168.0.2:8118/"

export use_proxy=on

This could be in ~/.bashrc (or other shell configuration file) or in /etc/profile. Both will accomplish the same thing. The advantage of using it in /etc/profile is that it applies to everyone using the computer. If it's in just your personal .bashrc file it only applies to your login.

Enjoy

VMWare Installation

I had to install my compiler and make with the commands:

# apt-get install gcc
# apt-get install make

I had to install a current kernel with the command:

# apt-get install linux-headers-$(uname -r)

Then I ran into additional problems because the linux source directory was not available. This was solvd by listing the directory /usr/src/ to determine the current version of the source files, and linking to it.

# ls /usr/src
drwxr-xr-x 20 root root 4096 2008-07-05 15:09 linux-headers-2.6.24-19
drwxr-xr-x  6 root root 4096 2008-07-05 15:09 linux-headers-2.6.24-19-server

# ln -s linux-headers-2.6.24-19-server/ linux

Then the following error occurred:

make[2]: *** [/tmp/vmware-config0/vmmon-only/linux/driver.o] Error 1
make[1]: *** [_module_/tmp/vmware-config0/vmmon-only] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-19-server'
make: *** [vmmon.ko] Error 2
make: Leaving directory `/tmp/vmware-config0/vmmon-only'
Unable to build the vmmon module.

For more information on how to troubleshoot module-related problems, please visit our Web site at "http://www.vmware.com/download/modules/modules.html" and "http://www.vmware.com/support/reference/linux/prebuilt_modules_linux.html".

Execution aborted.

This is related to the VMMon modules and has any easy fix by downloading the vmware-any-any module (see the http://www.vmware.com/support/reference/linux/prebuilt_modules_linux.html link for a link to Petr Vandrovec's website). Then you can run the runme.pl script yourself.

This generated the following messages:

VMware 2 or VMware Express detected, building for VMware 2, VMware Express and VMware  Workstation 4.0.x.
Using 2.6.x kernel build system.
make: Entering directory `/tmp/vmware-config1/vmmon-only'
make -C /usr/src/linux/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules
make[1]: Entering directory `/usr/src/linux-headers-2.6.24-19-server'
CC [M]  /tmp/vmware-config1/vmmon-only/linux/driver.o
CC [M]  /tmp/vmware-config1/vmmon-only/linux/driverLog.o
CC [M]  /tmp/vmware-config1/vmmon-only/linux/hostif.o
CC [M]  /tmp/vmware-config1/vmmon-only/common/comport.o
CC [M]  /tmp/vmware-config1/vmmon-only/common/cpuid.o
CC [M]  /tmp/vmware-config1/vmmon-only/common/hash.o
CC [M]  /tmp/vmware-config1/vmmon-only/common/memtrack.o
CC [M]  /tmp/vmware-config1/vmmon-only/common/phystrack.o
CC [M]  /tmp/vmware-config1/vmmon-only/common/task.o
gcc: error trying to exec 'cc1plus': execvp: No such file or directory
make[2]: *** [/tmp/vmware-config1/vmmon-only/common/task.o] Error 1
make[1]: *** [_module_/tmp/vmware-config1/vmmon-only] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.24-19-server'
make: *** [vmmon.ko] Error 2
make: Leaving directory `/tmp/vmware-config1/vmmon-only'
Unable to build the vmmon module.

For more information on how to troubleshoot module-related problems, please visit our Web site at "http://www.vmware.com/download/modules/modules.html" and "http://www.vmware.com/support/reference/linux/prebuilt_modules_linux.html".

Execution aborted.

This told me I needed to install g++ as well.

# apt-get install g++

I still continued to have trouble, mainly I couldn't connect to the bridged network. Running the following command also helped:

# apt-get install ia32-libs

Then I was able to finally run the install commands:

# cd /home/install/vmware-server-distrib/
# ./vmware-install.pl

And when that errored our, I ran the following commands:

# cd /home/install/vmware-any-any-update115
# ./runme.pl

To solve the following error:

timb@pc018:~$ vmware &
[1] 12350
timb@pc018:~$ /usr/lib/vmware/bin/vmware:  /usr/lib/vmware/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib32/libcairo.so.2)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib32/libcairo.so.2)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib32/libstdc++.so.6)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib32/libcairo.so.2)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib32/libcairo.so.2)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib32/libstdc++.so.6)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_3.4' not found (required by /usr/lib32/libcairo.so.2)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libpng12.so.0/libpng12.so.0: no version information available (required by /usr/lib32/libcairo.so.2)
/usr/lib/vmware/bin/vmware: /usr/lib/vmware/lib/libgcc_s.so.1/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib32/libstdc++.so.6)
[1]+  Done                    vmware

Then I had to install gcc-3.4 and g++-3.4 with the following commands:

# apt-get install gcc-3.4
# apt-get install g++-3.4

And I got VMware to run.

VMWare VFS Error

I recently converted my system from SuSE 10.1 to OpenSuSE 10.2. When I upgraded VMware to v5.5.2, I was no longer able to change which ISO file I was using for Knoppix (that's how I discovered it at any rate). Turns out the issue was a little larger than that as something broke the virtual file system (VFS). From the VMware web site ( http://www.vmware.com/community/thread.jspa?messageID=545298) noticed that other people were having the same issue.

The actual error was The Folder could not be displayed - VFS error: Invalid parameters. Further on, a found a reference that fixed it for me. By logging on as root, and executing the following statements:

# cd /usr/lib/vmware/lib
# mv libpng12.so.0 libpng12.so.0.old
# ln -sf /usr/lib/libpng12.so.0
# mv libgcc_s.so.1 libgcc_s.so.1.old
# ln -sf /lib/libgcc_s.so.1

I was able to get VMware working again. This is specifically for VMware Workstation 5.5.2 on OpenSuSE 10.2. This is only documented because some people may find a similar problem in the future with different libraries.

VMWare on OpenSuSE

I recently converted my system from SuSE 10.1 to OpenSuSE 10.2. When I upgraded VMware to v5.5.2, I was no longer able to change which ISO file I was using for Knoppix (that's how I discovered it at any rate). Turns out the issue was a little larger than that as something broke the virtual file system (VFS). From the VMware web site ( http://www.vmware.com/community/thread.jspa?messageID=545298) noticed that other people were having the same issue.

The actual error was The Folder could not be displayed - VFS error: Invalid parameters. Further on, a found a reference that fixed it for me. By loggng on as root, and executing the following statements:

cd /usr/lib/vmware/lib
mv libpng12.so.0 libpng12.so.0.old
ln -sf /usr/lib/libpng12.so.0
mv libgcc_s.so.1 libgcc_s.so.1.old
ln -sf /lib/libgcc_s.so.1

I was able to get VMware working again. This is specifically for VMware Workstation 5.5.2 on OpenSuSE 10.2.

Computer History

Computer System Computer History

Timothy J. Bruce

PC001

  • Style: Generic PC/XT
  • Source: Island Micro, Inc (Seattle, WA)
  • CPU: NEC V20
  • Mass Storage: 20 Mb Hard drive
  • RAM: 640Kb RAM
  • Video: CGA Video Card
  • Monitor: Color Composite Monitor
    • Upgraded to EGA about 1988
  • Modem: 1200 Baud Modem
    • Upgraded to 2400 Baud
  • Operating System: MS DOS 3.0
  • Purchased: August 1986
  • Disposed: 1991? (Sold)

PC002

  • Style: ?? TI 99/4A
  • Mass Storage: Data Cassette
  • Purchased: May 1989
  • Disposed: 1994? (Goodwill)

PC003

  • Style: Generic 80386
  • Source: Sysper Technologies (San Jose, CA)
  • CPU: 80386 / 25 MHz
  • Mass Storage: 1.2 Mb Floppy
  • Mass Storage: 1.4 Mb Floppy
  • Mass Storage 100 Mb Hard drive
    • Added 212 MB Hard drive Nov 92
    • Replaced 100 Mb Hard drive with 340 Mb Jan 94
  • RAM: 2 Mb RAM
  • Video Card: Super VGA (with 1 Mb Video RAM)
  • Modem: 2400 Baud Modem
  • Accessories: Logitech Serial Mouse
  • Operating System: MS DOS 4.01
  • Purchased: February 1991
  • Disposed: 1998? (Surplus – Free Geek?)

PC004

  • Style: BSR (ARC) 386 SX
  • Source: DAK Industries, Inc
  • CPU 80386 SX / 16 MHz
  • Purchased: November 1992
  • Disposed: 1996 (Sold?)

PC005

  • Style: Bondwell DAK Industries, Inc
  • CPU: 80386 SX (?) Notebook
  • RAM: 1 MB Ram
  • Mass Storage: 10 Mb Hard drive
  • Purchased: Apr 1993?
  • Disposed: 1995 (Sold)

PC006

  • Style: Generic (Custom Built) California Computer Show (Santa Barbara?)
  • CPU: Pentium 166 MHz MMX
  • Video: ATI Video Tuner
  • RAM: 4 Mb RAM
  • Mass Storage: 540 Mb Harddrive
    • Upgraded to 6 Gb (Apr 1998)
  • Purchased April 1997
  • Disposed: N/A
  • IP Address: 192.168.10.6

PC007

  • Style: Desktop
  • CPU: Style: AMD K6-2 350 MHz
  • Source: Affordable Technology (Beaverton, OR)
  • Purchased: February 1999
  • Disposed: N/A
  • Purpose: Kid’s Computer
  • IP Address: DHCP

PC008

  • Style: Compaq 486 DX50 Laptop
  • CPU: 486 DX50
  • Source: Sane Technology (Seattle, WA)
  • Mass Storage: 100 Mb Parallel Zip Drive
  • Mass Storage: 300 Mb Harddrive
  • Purchased: February 1999
  • Disposed: Jun 2000 (System failure)

PC009

  • Style: Micron P5 / 133 MHz Laptop
  • Purchased: July 2001
  • Disposed: N/A
  • Purpose: Family Laptop
  • IP Address: DHCP

PC010

  • Style: Custom Built Intel 1.5 GHz Mid Tower
  • CPU: Pentium 4 – 1.5 GHz
  • Source: Fry’s Electronics (Seattle, WA)
  • Mass Storage: 100 Mb Parallel Zip Drive
  • Mass Storage: 300 Mb Harddrive
  • Purchased: Oct 2002
  • Disposed: N/A
  • Purpose: My Main Desktop
  • IP Address: 192.168.10.9

PC011

  • Style: Desktop PC
  • CPU: AMD
  • Source: Beaverton, OR
  • Purchased: June 2002
  • Disposed: N/A
  • Purpose: Replacement for PC009

PC012

  • Style: Compaq Deskpro
  • Source: Budget Computers (Beaverton, OR)
  • CPU: Pentium II – 32 Mb RAM
  • Purchased: September 2002
  • Disposed: N/A
  • Purpose: Freesco Router DNS Services

PC013

  • Style: Dell Dimension (Dell Tag: EI10U)
  • Source: Fiserv EFT (Surplus)
  • CPU: Pentium III – 550 MHz
  • RAM: 0 Mb RAM
    • (Added 256 Mb)
  • Mass Storage: 6 Gb Hard drive
  • Purchased: December 2003
  • Disposed: N/A
  • Purpose: Windows 2003 Server DHCP File Server DNS Active Directory

PC014

  • Style: Dell Dimension (Dell Tag: E6LDA)
  • Source: Fiserv EFT (Surplus)
  • CPU: Pentium III – 550 MHz
  • RAM: 64 Mb RAM
    • Replaced with 512 Mb
  • Mass Storage: 0 Gb Hard drive
    • Added 80 Gb
  • Purchased: December 2003
  • Disposed: N/A
  • Purpose: Linux Server Apache File Server MySQL Database Server

Updates: 14 Jun 2007

PC015

  • Style: Hewlett Packard
  • CPU: AMD Athlon 64, 3500+
  • RAM: 512 Mb RAM
  • Mass Storage: 200 Gb Hard drive
  • Monitor: 19" HP Flat screen monitor
  • Purchased: November 2006
  • Disposed: N/A
  • Purpose: Linux Desktop (Originally this had Windows Media Center installed. The hard drive failed after 3 months, so HP, after many support calls, shipped a new one. However, no backup of the system was taken after it was setup. The new hard drive had no Operating System, and HP had no DVDs in stock, so I installed Ubuntu Feisty Fawn (v7.04) on the system, and it has worked very well as a network workstation. Lightweight word processing, picture viewing, email, and web surfing.)

PC016

  • Style: Hewlett Packard HP Pavillion DV6000 series (Model DV6253CL)
  • CPU: AMD Athlon 64
  • RAM: 2 Gb RAM
  • Mass Storage: 120 Gb Hard drive
  • Purchased: February 2007
  • Disposed: N/A
  • Purpose: Linux Laptop (Development / Software Testing) (Originally this had Windows Vista installed. I tried various Linux distributions and settled on Kubuntu (Feisty Fawn - v7.04) as it seemed to recognize the most components (I did have trouble with the Wireless card and finally got that working on Jun 12.) and had minimal problems booting. I did try OpenSuSE v10.2, v10.3 Alpha 3, and some Debian Sarge and Debian Etch. All of them had problems with one or more components. I am running this system with the Expansion base (XB3000) and bought VMware workstaion v6.00 for testing / development. More info later.)

PC017

PC018

  • Purpose:

PC019

PC020

PC021

PC022

PC023

  • Style: Mid-size Tower
  • CPU: Intel Core i5

PC024

PC025

PC026

space.sh

This shell script is used to show me how much space a particular directory takes up. The idea came to me while I was looking at filelight at one point because I was wondering hot much space some directories are taking on one of my systems. I could see the space used by a directory (and all it's subdirectories), but I wanted a way to see that space usage from the command line as well. Maybe someone had already written it, but this was my first pass at it back in 2005.

#! /bin/sh
echo
du $DIR --max-depth=1 -k 2>/dev/null

Then I made some improvments so I could run it against either my current directory or against a path I had permissions to, giving me the current version below:

#! /bin/sh
DIR=$1

if [ -z $1 ]; then
   DIR=.
fi

echo -n "Displaying size of: "
if [ $DIR = "." ]; then
   echo `pwd`
else
   echo "$DIR"
fi
echo -e '\n'
du $DIR --max-depth=1 -k 2>/dev/null

I'm sure further improvements could be made, but this gives me a quick view of the space used. Sometimes I use this with space.sh | sort -n to sort my directories in numerical order so I can easily see which are the largest subdirectories.

Installation of Freesco Packages

It’s really not tough, but I always seem to forget how to install a package to Freesco. Just use the following command from the freesco command line (remember you must be root to do this)

pkg -i pathname

Pathname would be the location of the package, usually in http: format.

For instance, the installation of the Dinjite’s Utils package for 0.3.x would be:

pkg -i http://dingetje.homeip.net/packages/0.3.x/utils_1.1_dingetje

There are a lot of add-on packages you can add to extend the functionality of FreeSCO. ONe source of additional packages can be found at http://www.freescosoft.com/ which links to a variety of sources. You may also find other packages linked in various forums in the Freesco support forums (http://forums.freesco.org/support).

NOTE: This package (the Dingetje's Utils package) is not listed with the normal packages in the Freescosoft web site. The only reference I found was in the Support Forums (http://forums.freesco.org/support/index.php?showtopic=12984&hl=utils_1.1_dingetje). Feel free to explore for other packages that meet your needs.

ASCII Chart

Occasionally, I have a need to look up a particular ASCII code when I'm writing writing some software. This is a reference for me, so I can easily find the list of printable ASCII characters.

The list of printable ASCII characters

33 !   34 "   35 #   36 $   37 %
38 &   39 '   40 (   41 )   42 *
43 +   44 ,   45 -   46 .   47 /
48 0   49 1   50 2   51 3   52 4
53 5   54 6   55 7   56 8   57 9
58 :   59 ;   60 <   61 =   62 >
63 ?   64 @   65 A   66 B   67 C
68 D   69 E   70 F   71 G   72 H
73 I   74 J   75 K   76 L   77 M
78 N   79 O   80 P   81 Q   82 R
83 S   84 T   85 U   86 V   87 W
88 X   89 Y   90 Z   91 [   92 \
93 ]   94 ^   95 _   96 `   97 a
98 b   99 c   100 d   101 e   102 f
103 g   104 h   105 i   106 j   107 k
108 l   109 m   110 n   111 o   112 p
113 q   114 r   115 s   116 t   117 u
118 v   119 w   120 x   121 y   121 z
123 {   124 |   125 }   126 ~   127  

There are also some higher order character that show up in ASCII, but those are dependent on the code page that is loaded. One provides a "line art" set of character for drawing lines and double lines to make boxes and other emphasis and other provide a limited set of characters from some foreign languages. If you want more information on these, please search on "code pages" with your favorite search engine.

MSSQL Active Users

Sometimes you want to be able to list the active users, and you can use the system stored procedures of sp_who and sp_who2 to do that. However, I've found that it's inconvenient for a couple of reasons.

  1. If you run it from a command line, it scrolls over the 80 column limit you usually have in a terminal session (sometimes I run this using a command like osql -E -S sql -Q 'exec master..usp_ListUsers'). While this also goes over the 80 column limit, it goes over 2 lines, so it's more readable to me.
  2. This allows you to enter either a database name or a user name and filter the output so you only see those results. In this way, I can see the users who are currently connected to master, msdb, or some other user database inside SQL Server. I just feel this gives me more flexibility in looking at what's going on with the server.
PRINT 'Building usp_ListUsers - Starting'
GO

IF NOT ( object_id ( 'usp_ListUsers' ) is NULL )
BEGIN
   DROP PROCEDURE usp_ListUsers
END
GO

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
SETUSER  'dbo'
GO

CREATE PROCEDURE usp_ListUsers
   @astr_database VARCHAR (50) = NULL,
   @astr_user VARCHAR (50) = NULL
AS
BEGIN

/*********************************************************************
NAME:  usp_ListUsers

DATABASE:
   master

PARAMETERS:
   astr_Database - (Optional) The database to report on (list users in)
   astr_User - (Optional) The user to find and report on

ASSUMPTIONS:
   NONE

COMMENTS:
   NONE

AUTHOR(S):
   TJB - Timothy J. Bruce

PURPOSE:

MODIFICATION HISTORY

Init  Date      Comments
TJB   07Mar02   Initially Created

*********************************************************************/

/* Declare Variables */

   DECLARE @lstr_Database CHAR ( 20 )
   DECLARE @lstr_Error1 CHAR ( 50 )
   DECLARE @lstr_Error2 CHAR ( 50 )
   DECLARE @lstr_user VARCHAR ( 50 )

   DECLARE @llng_Count INTEGER
   DECLARE @llng_DBID INTEGER

/* Set up the Environment */

   SET NOCOUNT ON

/* Begin Processing */

   IF @astr_database IS NOT NULL
   BEGIN
       IF db_id ( @astr_database ) IS NULL
       BEGIN
       -- If there is no associated db_id, it doesn't exist.
            SELECT @lstr_Error1 = 'The database name you entered ('
            SELECT @lstr_Error2 = ') is not valid for this server.'
            SELECT 'Error'=@lstr_Error1 + @astr_database + @lstr_Error2
            RETURN ( -1 )
       END
       ELSE
       BEGIN
       -- Found the database - lets list all the users in it.
           --SET 'DB' = @astr_database
           SELECT
               spid,
               'Status' = CONVERT ( CHAR(10), status ),
               'login' = CONVERT ( CHAR (15), loginame),
               'NT Account' = CONVERT ( CHAR (12), nt_username),
               'Workstation Id' = CONVERT ( CHAR (15), hostname),
               blk = CONVERT ( CHAR (5), blocked),
               dbname = CONVERT ( CHAR (20), db_name(dbid) ),
               'Program' = CONVERT ( CHAR (10), program_name),
               'Command' = CONVERT ( CHAR (20), cmd )
           FROM
               master.dbo.sysprocesses
           WHERE
               spid BETWEEN 0 and 32767 AND
               dbid = db_id ( @astr_database )
           ORDER BY
               loginame,
               hostname,
               spid
       END
   END
   ELSE
   BEGIN
       IF @astr_user IS NOT NULL
       BEGIN
           SELECT @lstr_user = '%'+ @astr_User + '%'
           SELECT @llng_Count = COUNT(*) FROM master..sysprocesses WHERE UPPER ( nt_username ) LIKE UPPER ( @lstr_user )
           IF @llng_Count  = 0
           BEGIN
               SELECT 'Error' = 'User ''' + @astr_User + ''' could not be found.'
               RETURN ( -2 )
           END
           ELSE
           BEGIN
               SELECT
                   spid,
                   'Status' = CONVERT ( CHAR(10), status ),
                   'login' = CONVERT ( CHAR (15), loginame),
                   'NT Account' = CONVERT ( CHAR (12), nt_username),
                   'Workstation Id' = CONVERT ( CHAR (15), hostname),
                   blk = CONVERT ( CHAR (5), blocked),
                   dbname = CONVERT ( CHAR (20), db_name(dbid) ),
                   'Program' = CONVERT ( CHAR (10), program_name),
                   'Command' = CONVERT ( CHAR (20), cmd )
               FROM
                   master.dbo.sysprocesses
               WHERE
                   spid BETWEEN 0 and 32767 AND
                   UPPER ( nt_username ) LIKE UPPER ( @lstr_user )
               ORDER BY
                   loginame,
                   hostname,
                   spid
           END
       END
       ELSE
       BEGIN
           /* All Users & Processes */
           SELECT
               spid,
               'Status' = CONVERT ( CHAR(10), status ),
               'login' = CONVERT ( CHAR (15), loginame),
               'NT Account' = CONVERT ( CHAR (12), nt_username),
               'Workstation Id' = CONVERT ( CHAR (15), hostname),
               blk = CONVERT ( CHAR (5), blocked),
               dbname = CONVERT ( CHAR (20), db_name(dbid) ),
               'Program' = CONVERT ( CHAR (10), program_name),
               'Command' = CONVERT ( CHAR (20), cmd )
           from
               master.dbo.sysprocesses
           where
               spid BETWEEN 0 and 32767
           ORDER BY
               loginame,
               hostname,
               spid
       END
   END
   RETURN ( 0 )
END

GRANT EXECUTE ON usp_ListUsers TO PUBLIC

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SETUSER
go

PRINT 'Building usp_ListUsers - Finished'
GO

If you have any questions, feel free to contact me.