Archive for the 'OS' Category

Windows: Add Copy-to and Move-to folder to context menu

Tuesday, September 4th, 2012

I spend a lot of time copying and moving files between folders. More often than not, when I click on a file in Explorer, I want to copy or move it to another folder. That means I spend a good deal of time dragging files around or copying and pasting them.

But with a Registry entry, you can save yourself time: you can add Copy To Folder and Move To Folder options to the right-click context menu. When you choose one of the options from the menu, you get a dialog that will let you choose the location to copy or move the file to, and then send the file there.

To add the option, run the Registry Editor (regedit) and go to

HKEY_CLASSES_ROOTAllFilesystemObjectsshellexContextMenuHandlers.shellex

This tells you it’s a shell extension key that lets you customize the user shell or the interface. Create a new key called “Copy To”.

Set the value to

{C2FBB630-2971-11d1-A18C-00C04FD75D13}.

Create another new key called “Move To”. Set the value to

{C2FBB631-2971-11d1-A18C-00C04FD75D13}.

Exit the Registry.

The changes should take effect immediately. The Copy To Folder and Move To Folder options will appear. When you right-click on a file and choose one of the options, you’ll be able to move or copy the file using a dialog box like the

DOS: Capture return values from commands

Wednesday, February 8th, 2012

When I am writing build automation scripts, there are times that I have to insure that the previous command completed
with no errors. I have found that ERRORLEVEL gets filled in with the return value from a command.

dir %1

if (%ERRORLEVEL%) == (0) echo Found File: %1
if (%ERRORLEVEL%) == (1) echo Missing File: %1

So if you save the previous in a file and run the command with one (1) argument, it will display the output of the dir command
but also print either “Found file: ” or “Missing File: “.

Tags: ,

Dos: Adding commands to the PATH

Tuesday, December 20th, 2011

When you install a new piece of software that does not add itself to the Windows PATH variable, you may find your self
needing it to be run from a command prompt. You could type the full command path each time you run the executable, but
it may be easier to add the directory to the PATH variable so that it is always available.

To add it for the current command prompt:

set PATH=%PATH%;"C:Program FilesSometool"

This will add the variable to the current command prompt environment but will go away once you close the window and will not
be available to other prompts unless you type it in again.

To add it to the Windows Environment, you can use the My Computer->Properties menu to select the “Advanced System Settings”
in Windows 7 to then select the “Environment Variables…”. Now the choice you have is to add it to the System variables or
the User variables for.

If you choose the System varables you will be adding it to the system as a whole and any other user who logs in will have
the updated path. If you add it to the User variables, then it is only available to your user.

Whichever you choose, select the Path entry and click the “Edit…” button. This will pop up a dialog that will let
you add to the “Variable Value” entry. Now you will need to decide whether you want your new path at the beginning, end,
or somewhere in the middle. You might add it to the beginning if it is being used to override an existing command. You
may add to the end if there is no conflict with other installs. And finally, you may need to choose the middle if there
are some commands you need to override but others that need to be left alone.

Entries are separated by the semi-colon “;” character in DOS.

Tags: ,

Using Rsync to backup a directory

Monday, November 21st, 2011

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.

DOS: Check for empty environment variable

Wednesday, November 16th, 2011

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.

Tags: ,

Linux:Script to use find to search contents of files

Thursday, November 3rd, 2011

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.

Tags:

Linux: Processor info and speed

Thursday, October 27th, 2011

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.

Tags: , ,

Viewing many different video formats on Windows

Monday, October 3rd, 2011

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.

Tags: ,

Linux System utilization tools

Friday, September 2nd, 2011

I was asked about system utilization on Linux systems. I found thesystatset of tools which consist of: sar, sadf, mpstat, iostat, nfsiostat, cifsiostat, pidstat and sa tools.

I will talk about the iostat tool in this article and follow up about some of the other tools.

On Ubuntu or debian systems you can install this toolset with:

sudo apt-get install sysstat

Then you will have access to the iostat command. The command output from executing with no options is below:

# iostat
Linux 2.6.32-33-generic (sumo)  09/01/2011      _i686_  (2 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.11    0.00    0.47    0.01    0.00   99.41

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sda               0.54         1.85         8.91    1611385    7740024

This displays the avg-cpu utilization and a device usage list with basic utilization.
Some options you can use are

Option Explanation
-c Display CPU utilization only
-d Display Device utilization only
-k Display information in kilobytes
-m Display information in megabytes
-t Display time for each report
-x Display extended statistics

One more way to use the iostat tool is to specify an interval and count to the command

iostat -d -x 10 5

This will display the output 5 more times with 10 seconds between each run.

Tags: , ,

Cron Job entry format

Friday, August 26th, 2011

If you ever need to schedule a job regularly on a Unix system, they have a great utility called cron. This will run a job at a regularly scheduled time.

Here is the format:

* * * * *  command to be executed
_ _ _ _ _ 
| | | | |
| | | | +--- day of week (0 = Sunday - 6 = Saturday)
| | | +----- month (1 - 12)
| | +------- day of month (1-31)
| +--------- hour(0-23)
+----------- minute (0-59)

example of a script that runs every day at 7:

* 7 * * * sendmeupdate