Random Wisdom

How To …

Linux authentication using LDAP

by on Feb.27, 2007, under How To ..., Linux, Software

There’s a lot of information out there but none really provide a step-by-step guide that would be useful to a novice:

This one however, sheds some light on the bigger picture:

LDAP Authentication In Linux

Once the initial configuration of the server is complete, LDAP Browser/Editor serves as a very useful client/admin tool.

Leave a Comment :, , more...

Cross-platform filesystem access

by on Nov.21, 2006, under How To ..., Linux, Software

Looks like the ntfs-3g driver has already gained a lot of popularity and is quite easy to use:

NTFS-3G Read/Write Driver

The driver itself is supposedly available from the Fedora Extras repository for FC6 onwards. Completely safe read/write access to NTFS drives from Linux — now that’s a dream come true!

In the meanwhile, it looks like there’s also a windows Ext2 file-system driver that allows full read/write access to Ext2/3 volumes:

Ext2 Installable File System For Windows

Of course, one of the drawbacks here is that the Ext3 volume is mounted as Ext2 — so there is no journaling support. In case of a ‘dirty’ unmount e2fsck will have to be run. The other drawback is the fact that is won’t work with LVM.

So, these drivers really open up a lot of choices. But I guess the best option is to have the shared drive as NTFS since the ntfs-3g driver takes care of journaling.

Leave a Comment :, , , , , more...

BASH as a simple calculator

by on Sep.25, 2006, under How To ..., Linux, Software

As long as you are satisfied with integer results:

[darkknight@darkworld ~]$ echo $[32 * 98]
3136
[darkknight@darkworld ~]$ echo $[332 / 98]
3
[darkknight@darkworld ~]$ echo $[29 + 56]
85
[darkknight@darkworld ~]$ echo $[29 - 156]
-127

For full precision, one can use bc:

$ bc -l
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'. 
332/98
3.38775510204081632653
7 Comments :, , more...

Cropping a PDF Document

by on Jul.31, 2006, under How To ..., LaTeX, Software

Easily accomplished using pdftops:

$ pdftops -paperw WIDTH \
             -paperh HEIGHT \
             -noshrink -expand document.pdf && ps2pdf document.ps

WIDTH and HEIGHT are in points — they basically specify the dimensions of the image to be cropped.

Content is extracted from the center of the page. This technique is specially useful as a bypass for using psfrag with pdfLatex:

  • Save EPS figure with TAGS
  • Create a very simple tex document that simply includes the figure (centered) with psfrag replacements and run latex -> dvips -> ps2pdf
  • Follow the step above to crop out the figure.

The cropped out figure will have the TAGS replaced and be in PDF format — ready to be used with pdfLatex!

UPDATE [16 July 2009] It looks like pdfcrop might actually be a better option:

$ pdfcrop --help
PDFCROP 1.5, 2004/06/24 - Copyright (c) 2002, 2004 by Heiko Oberdiek.
Syntax:   pdfcrop [options] <input[.pdf]> [output file]
Function: Margins are calculated and removed for each page in the file.
Options:                                                    (defaults:)
  --help              print usage
  --(no)verbose       verbose printing                      (false)
  --(no)debug         debug informations                    (false)
  --gscmd <name>      call of ghostscript                   (gs)
  --pdftexcmd <name>  call of pdfTeX                        (pdftex)
  --margins "<left> <top> <right> <bottom>"                 (0 0 0 0)
                      add extra margins, unit is bp. If only one number is
                      given, then it is used for all margins, in the case
                      of two numbers they are also used for right and bottom.
  --(no)clip          clipping support, if margins are set  (false)
  --(no)hires         using `%%HiResBoundingBox'            (false)
                      instead of `%%BoundingBox'
  --papersize <foo>   parameter for gs's -sPAPERSIZE=<foo>,
                      use only with older gs versions <7.32 ()
Examples:
  pdfcrop --margins 10 input.pdf output.pdf
  pdfcrop --margins '5 10 5 20' --clip input.pdf output.pdf

The tool comes as a part of the ‘tetex’ package.

Leave a Comment :, , , , more...

Creating directory hierarchies in bash

by on Jul.16, 2006, under How To ..., Linux, Software

The BASH ‘brace expansion‘ feature can be used to create whole directory trees using a single command. From the man page for BASH:

Brace Expansion
       Brace expansion is a mechanism by which arbitrary strings may be gener?
       ated.   This  mechanism is similar to pathname expansion, but the file?
       names generated need not exist.  Patterns to be brace expanded take the
       form of an optional preamble, followed by either a series of comma-sep?
       arated strings or a sequence expression between a pair of braces,  fol?
       lowed  by  an  optional  postscript.   The preamble is prefixed to each
       string contained within the braces, and the postscript is then appended
       to each resulting string, expanding left to right.

       Brace  expansions  may  be nested.  The results of each expanded string
       are not sorted;  left  to  right  order  is  preserved.   For  example,
       a{d,c,b}e expands into `ade ace abe'.

       A  sequence  expression takes the form {x..y}, where x and y are either
       integers or single characters.  When integers are supplied, the expres?
       sion  expands  to each number between x and y, inclusive.  When charac?
       ters are supplied, the expression expands  to  each  character  lexico?
       graphically between x and y, inclusive.  Note that both x and y must be
       of the same type.

       Brace expansion is performed before any other expansions, and any char?
       acters  special to other expansions are preserved in the result.  It is
       strictly textual.  Bash does not apply any syntactic interpretation  to
       the context of the expansion or the text between the braces.

       A  correctly-formed  brace  expansion must contain unquoted opening and
       closing braces, and at least one unquoted comma  or  a  valid  sequence
       expression.   Any incorrectly formed brace expansion is left unchanged.
       A { or , may be quoted with a backslash to prevent its being considered
       part  of  a brace expression.  To avoid conflicts with parameter expan?
       sion, the string ${ is not considered eligible for brace expansion.

       This construct is typically used as shorthand when the common prefix of
       the strings to be generated is longer than in the above example:

              mkdir /usr/local/src/bash/{old,new,dist,bugs}
       or
              chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}

       Brace  expansion  introduces  a  slight incompatibility with historical
       versions of sh.  sh does not treat opening or closing braces  specially
       when  they  appear as part of a word, and preserves them in the output.
       Bash removes braces from words as a  consequence  of  brace  expansion.
       For  example,  a word entered to sh as file{1,2} appears identically in
       the output.  The same word is output as file1 file2 after expansion  by
       bash.   If strict compatibility with sh is desired, start bash with the
       +B option or disable brace expansion with the +B option to the set com?
       mand (see SHELL BUILTIN COMMANDS below).

So, for example:

$ mkdir -p root/{1/{1.1,1.2,1.3},2,3/{3.1,3.2/{3.2.1,3.2.2}}}

$ tree
.
`-- root
    |-- 1
    |   |-- 1.1
    |   |-- 1.2
    |   `-- 1.3
    |-- 2
    `-- 3
        |-- 3.1
        `-- 3.2
            |-- 3.2.1
            `-- 3.2.2

11 directories, 0 files

The ‘-p’ option to mkdir makes it create the parent directories if they do not exist.

Leave a Comment :, more...

Installing MS TrueType core fonts on Linux

by on May.31, 2006, under How To ..., Linux, Software

Instructions obtained from:
http://corefonts.sourceforge.net/

  1. Install cabextract and fedora-rpmdevtools:
    $ sudo yum install cabextract fedora-rpmdevtools
  2. Create the build tree:
     $ fedora-buildrpmtree 
  3. Get the SPEC file:
    $ cd ~/rpmbuild/SPEC && \
      wget http://corefonts.sourceforge.net/msttcorefonts-2.0-1.spec
  4. Get the fonts and create the RPM package:
     $ rpmbuild -bb msttcorefonts-2.0-1.spec 
  5. Install the fonts package:
     $ sudo rpm -ivh ../RPMS/noarch/msttcorefonts-2.0-1.noarch.rpm 

Restart any running application to use the new fonts.

Leave a Comment :, , more...

Installing RPMs as a regular user

by on Apr.20, 2006, under How To ..., Linux, Software

A while back I needed some packages on a machine that I don’t have admin rights to. Grabbing the source and recompiling would have been a pain the a** so I decided to read the rpm man pages and look for a way to install packages in the user home directory. Since it’s such a nice package manager, it comes with options that allows me to do just that. The command needed is:

$ rpm -ivh --relocate OLDPATH1=NEWPATH1 [--relocate OLDPATH2=NEWPATH2 ...] \
      --badreloc package.rpm

where OLDPATH is the path in the package; and NEWPATH is something like /home/user/userroot/usr, etc.

It’s best to run

$ rpm -qpl package.rpm

to see exactly which paths are going to be used by the package. For example, if the package foo.rpm produces:

$ rpm -qpl foo.rpm
/usr/bin/foo
/usr/lib/foo.so.0.0
/usr/lib/foo.so.0
/usr/share/doc/foo/README

then the steps needed are:

$ mkdir -p ~/myroot/usr/bin ~/myroot/usr/lib ~/myroot/usr/share/doc
$ rpm -ivh --relocate /usr=/home/$USER/myroot/usr --badreloc foo.rpm

That’ll install the package under the hierarchy ~/myroot. There will some errors from rpmdb but this is fine since the rpmdb is in a filesystem that we do not have write access to. The only repercussion is that rpm will have no record of the package foo being installed (so packages will have to be removed by hand); but that’s okay since we cannot possibly mess up the system while installing stuff under our own home dirs.

The only steps remaining are to add the new paths to the binary and library search paths. To so this, add the following lines to ~/.bash_profile

        PATH=$PATH:$HOME/myroot/usr/bin
        LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/myroot/usr/lib

        export PATH LD_LIBRARY_PATH

This is only efficient as long as the package does not have too many unmet dependencies — since you will need to grab and install all missing dependencies along with the package itself. And even if you had installed some of the dependencies earlier using this method, rpm will not know about it since there will be no entry in the system rpmdb.

Leave a Comment :, , more...

FC kernel rebuild HOWTO

by on Apr.20, 2006, under How To ..., Linux

Paul Howarth has a very nice article here:

http://www.city-fan.org/tips/TweakKernelPackage

The main benefit is that you can use rpmbuild to generate kernel RPMs using the same SPEC file as the distribution itself — resulting in packages that are as easy to handle as those from FC itself.

Leave a Comment :, , , more...

SSH automatic reconnect on timeout

by on Mar.15, 2006, under How To ..., Linux, Software

There may already be some builtin option that allows a client to reconnect when a timeout occurs but I was too lazy to look through the man pages. So I came up with line of bash commands that will do just that:


$ while [ 1 ]; do ssh user@host.domain; sleep 120; done

This will keep reconnecting to the host 120 seconds after a connection drops out for whatever reason. This is specially handy to make sure that a remote tunnel stays open. Right now I use it to reach a single host (A,http) on a remote private network from home (B) via another machine in the private network (C) and an intermediate SSH server (D):

  1. [user@C ~]$ while [ 1 ]; do ssh -R someport:A:80 user@D; sleep 120; done
  2. [user@B ~]$ ssh -L 80:localhost:someport user@D
  3. [root@B ~]# echo "127.0.0.1    A" >> /etc/hosts

Now it is possible to type “http://A” and visit the site from B as easily as from within the remote private network.

4 Comments :, more...

Prosper & PDF Output

by on Feb.24, 2006, under How To ..., LaTeX, Software

Prosper cannot be used with PDFTeX and hence PDF files must be obtained via the DVI -> PS -> PDF route. The default ps2pdf conversion, however, generates a PDF with pages that are a bit too narrow. This is easily remedied by specifying the size of the output desired to the ps2pdf program:


$ ps2pdf -dDEVICEWIDTHPOINTS=x -dDEVICEHEIGHTPOINTS=y somefile.ps

Where ‘x’ is the width in and ‘y’ is the height in 1/72″ units. So, for an approximately A4 size output, ‘x’=595 & ‘y’=842.

Leave a Comment :, , , more...