Categories
Windows 7

Can’t delete long or deep folder path

For a while now I’ve been using a scheduled backup that copies my windows profile to my file server on a nightly basis. Well since I switched to Vista and now Windows 7 I’ve noticed something funky.

If you look in your C:\users\<username>\AppData\Local (hidden folder) folder you’ll notice an "Application Data" directory with an icon that looks like it’s a shortcut and that you have no rights to access. Well it seems the Microsoft in all it’s wisdom created a junction point here that basically points back to itself.

So what happens when you have a backup solution that overrides access denied and then attempts to copy this folder is that you copy itself into itself over and over again until you reach the windows folder depth limit and error out. You end up with something like this but MUCH deeper

 folders.jpg

Well I search for about an hour and finally found a solution on Windows IT Pro, JSI Tip 9651.

By using RobCopy, which is now part of Vista and Windows 7, this script will automatically delete the deep/long folder structure. If you’re not runing Vista or Windows 7, make sure a copy of RoboCopy.exe is in the same folder as the batch file.

Copy and paste this into notepad and save as DelFolder.bat. The syntax is DelFolder.bat <FolderPath>:

@echo off
if {%1}=={} @echo Syntax: DelFolder FolderPath&goto :EOF
if not exist %1 @echo Syntax: DelFolder FolderPath – %1 NOT found.&goto :EOF
setlocal
set folder=%1
set MT="%TEMP%\DelFolder_%RANDOM%"
MD %MT%
RoboCopy %MT% %folder% /MIR
RD /S /Q %MT%
RD /S /Q %folder%
endlocal

Categories
Linux

Linux hugepage script for oracle

Here is the script to calculate hugepages for oracle db

#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
#
# Note: This script does calculation for all shared memory
# segments available when the script is run, no matter if it
# is an Oracle RDBMS shared memory segment or not.

# Check for the kernel version
KERN=`uname -r | awk -F. ‘{ printf("%d.%dn",$1,$2); }’`

# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk ‘{print $2}’`

# Start from 1 pages to be on the safe side and guarantee 1 free HugePage
NUM_PG=1

# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | awk ‘{print $5}’ | grep "[0-9][0-9]*"`
do
   MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
   if [ $MIN_PG -gt 0 ]; then
      NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
   fi
done

# Finish with results
case $KERN in
   ‘2.4’) HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
          echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
   ‘2.6’) echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
    *) echo "Unrecognized kernel version $KERN. Exiting." ;;
esac

# End
 

Categories
Openbsd

Adding color, colour to bash scripts

I was curious about just adding colour to echos that I do in scripts and here is how:

echo -e "This is red->e[00;31mREDe[00m"

 

I havent found out how the colours actually work (eg tables of colours) but if you experiment with the numbers you can come up with different foreground and background colours.

UPDATE:

Ok here is a script to dump out the various colour combos.

#/bin/sh
# Show all the colors of the rainbow, should be run under bash
for STYLE in 0 1 2 3 4 5 6 7; do
  for FG in 30 31 32 33 34 35 36 37; do
    for BG in 40 41 42 43 44 45 46 47; do
      CTRL="33[${STYLE};${FG};${BG}m"
      echo -en "${CTRL}"
      echo -n "${STYLE};${FG};${BG}"
      echo -en "33[0m"
    done
    echo
  done
  echo
done
# Reset
echo -e "33[0m"

 

 

Categories
Freebsd

Creating command line options in a bash script

Ok, so for a while I have done this a bunch of different ways but I think the best way I found is with a simple case statement. In here you can set variables, execute commands, functions, nest statements etc… It works out really well. here is a snippet to show you what i mean.

while [ $# -gt 0 ]
do
        case $1
        in
        -v)
                VERBOSE=YES
                shift 1
     
        ;;

        -l)
                echo "$MODULES"
                exit 0
        ;;

        -os)
                if [ -z $2 ]
                then
                        echo "You must choose a VERSION"
                        exit 1
                else
                        for MOD in $MODULES
                        do
                                if [ "$MOD" = "$2" ]
                                then
                                        LISTED=YES
                                fi
                        done
                        if [ "$LISTED" = "YES" ]
                        then
                                VERSION=$2
                                shift 2
                        else
                                echo "Module not found. Use -l for listing"
                                exit 1
                        fi
                fi
        ;;

        -h)
                HELPMENU
                exit 1
        ;;

        –help)
                HELPMENU
                exit 1
        ;;

        *)
                HELPMENU
                exit 1
        ;;
        esac
done