eTechtips

Tech Tips and Insights

Category: Software

  • Using Rsync to backup a directory

    Recently I was moving data between an old server and new web server. I had some 250 GB of data and thought about just using Secure Copy (scp). When I started the process, I walked away
    thinking “No Problem”, but after a few files, I got an error due to file permissions and I did not want to figure out what files had not been copied yet or where to try to restart.
    So I used rsync to mirror the drive. I was able to set it up and due to my slow network speed, it still took several days, but I was certain that I had gotten all the data.

    rsync -azuv -e ssh  user@originserver:public_html/* public_html/
    

    The options I used were for :

    Option Description
    -a Archive Mode
    -z Compress File Data
    -u Update Mode
    -v Verbose
    -e specify command to run

    This took some time to run, but I did not have to babysit the command and it duplicated the data from my old server to the new one.

    0 Comments
  • DOS: Check for empty environment variable

    I was writing a batch file the other day and needed to change the argumets to a command based on if the user had specified his password on the command line.

    SET PASS=somepassword
    : or
    :SET PASS=
    if x%PASS%= X (
      SET PASSARG=--password somepassword
    ) else
    (
      SET PASSARG=
    )
    
    commandtorun %PASSARG%
    

    Now if the user comments out his password, the script will make the PASSARG environment variable be empty or if they set a password the passarg variable will be filled in.

    0 Comments
  • Java: Command line argument processing

    In each language that I have learned I have found it useful to know how to process command line arguments and here is a simple framework that I use for Java. I usually wrap the java command line in a bat or shell file to make it easier to run so that the user does not have to worry about classpath or path issues.

    The following is the basic code to handle the command line arguments.

    class CmdArgs
    {
    
      public static void main(String[] args)
      {
          int argsize = args.length;
          String curarg;
    
          if (argsize > 0 )
          {
           
          }
          
          for(int i = 0; i < argsize; i++)
          {
              if (args[i].equals("--host"))
              {
                 i++;
                 host = args[i];
               }
              else if (args[i].equals("--debug"))
              {
                   debug = 1;
              }
              else
              {
                  System.out.println("Unknown option: " + args[i]);
                  System.exit(1);
              }
           }
    
       }
    }
    

    The bat file for Dos/Windows might look like this:

    @echo off
    
    java -cp c:javabin;somejar.jar  com.etechtips.CmdArgs %*
    

    The shell based file might look like:

    java -cp /home/ecdown/javabin:somejar.jar com.etechtips.CmdArgs $*
    
    0 Comments
  • Linux:Script to use find to search contents of files

    I use find and grep quite a bit. I found that I was regularly searching for strings in file and was typing commands like:

    find . -exec grep "somestring" {} ; --print
    

    This find command will search from the current directory and for each file will run grep on it and if it finds a matching string, it will print the string and then the filename. So I took this and moved it into a script.

    #!/bin/sh
    
    if [ $# -lt 1 ]; then
      echo 1>&2 Usage: $0 ""
      exit 127
    fi
    icase=
    search=
    
    while [ $# -ge 1 ]; do
      case $1 in
         -i) icase=$1;;
          *) search=$1 ;;
      esac
      shift
    done
    
    find . -type f -print0 | xargs -0 grep $icase $search
    

    This allows me to run a command such as

    ffind -i Super
    

    This command will search all file names starting from the current directory and recurse directories and the “-i” will tell it to ignore case.

    0 Comments
  • Linux: Processor info and speed

    There are times that I get on a Linux box and want to know about some of the resources available to me. There are tools that can accomplish this, but there are some files that contain basic settings about the resources available to the system. One of those file is:

    /proc/cpuinfo
    

    This file contains information about the Processors and you can do a simple:

    more /proc/cpuinfo
    

    to see all the details or you can grep for certain fields:

    processor       -- This will show you how many processor entries there are.
    cpu MHz  or MHz -- This will show you the speed of the processors.
    cache size      -- This will show you the cache size available to the processor.
    model           -- This will show you the type and model of the processor you are using.
    

    There are quite a few more fields, but these are the ones that I check the most.

    0 Comments
  • VI: Reload Current file

    When I am editing and having a “clumsy fingers” day, I find that I have to reload the file that I am editing from disk repeatedly. I usually just do a quick “:q!” and re-run the vi command that opened the file. But there is a better way!

    Use the :edit command:

    :edit
    

    Or you can shorten it to

    :e
    

    Now if you have typed in the window you are editing and want to reload from disk anyway without saving, remember to add the exclamation point(!) to the command.

    :edit!
    

    or

    :e!
    
    0 Comments
  • Firefox: Location bar behavior

    When you are typing in the location bar, you can have the suggestions come from your History, Bookmarks, Both or none.

    To update this, Goto Tools->Options.

    In the popup menu, select the privacy tab.

    At the bottom there is the Location bar section. Select the “When using the location bar, suggest:

    History and Bookmarks  
    History
    Bookmarks
    Nothing
    
    0 Comments
  • CSS: Background properties

    These are the individual background properties in CSS.

    background-color
    background-image
    background-repeat
    background-attachement
    background-position
    

    The background-color property specifies the color of the element. This can be useful to specify if someone has turned images off and you want a non-default view of your content. You can use a hex value (#RRGGBB), a shortcut hex value (#RGB) or a named color (red, green,blue).

    background-color: #fffffff;
    

    The background-image specifies an image to place in the background of an element. Remember that the image should be supported by as many browsers as possible. This means using jpeg, pngs or gifs, not tifs or proprietary image formats.

    background-image: url(images/someimage.gif)
    

    The background-repeat property specifies how an image should display within an element. You can have it repeat across (repeat-x), repeat downwards (repeat-y) or not repeat (no-repeat).

    background-repeat: repeat-x;
    

    The background-attachmemnt attribute is used to specify if an image should scroll (scroll) with the page, be fixed (fixed) to the page or inherit position from a parent element (inherit).

    background-attachment: fixed;
    

    The background-position attribute is used to specify the starting position of an image. This can be useful if you are using a sprite to speed up loading times. The background-position attribute can take a Xpx Ypx argument, an X% Y% argument, named arguments(left top, right bottom,…) or inherit from the parent.

    background-position: 50% 50%;
    

    Here is an example of the use of these:

     body {
       background-color: #ffffff;
       background-image: url(images/someimage.gif);
       background-repeat: no-repeat;
       background-attachment: fixed ;
       background-position: left top ;
    }
    

    You can also use a short cut method to the background property.

     .imagebox {
      background: #ffffff url(images/someimage.gif) no-repeat fixed right top;
    }
    
    0 Comments
  • Notepad++: Changing shortcut keys

    I was tracking a log file the other day and had to reload the file from disk regularly so I wanted to find out how to make a shortcut key to the Reload from disk menu entry on the File menu. Using the Settings->Shortcut Mapper to update the shortcuts for a given menu entry, I chose the Ctrl-R sequence but you are welcome to find an unmapped key sequence that works for you.

    0 Comments
  • Viewing many different video formats on Windows

    So I lost my hard drive and went to play some of the videos that I have saved on the system and could no longer play them in Windows Media Player. I needed to download a set of video codecs to play my .vob files. I am using the K-Lite Codec Pack.

    Featured Software

    VIDEO CODECS
    FFDShow MPEG-4
    DivX 8
    Koepi’s XviD Codec
    DScaler MPEG Filters
    Ogg Codecs
    Xvid Video Codec
    Nic’s XviD Codec
    Ligos Indeo Codec
    AUDIO CODECS
    MPEG Layer-3 Codec
    AC3 Filter
    AC-3 ACM Codec
    CoreVorbis Decoder
    LAME DirectShow Filter
    LAME MP3 Encoder
    Monkey’s Audio
    Vorbis Ogg ACM Codec

    This allows me to view the files in other video apps as well.

    0 Comments