Categories
Freebsd

Add timestamps to history

Add the following to your .bashrc:

export HISTTIMEFORMAT="%h/%d – %H:%M:%S "

The result is this:

[root@server ~]# history
    1  Mar/16 – 18:09:00 cd /etc
    2  Mar/16 – 18:09:10 vi fstab
    3  Mar/16 – 18:09:43 ls -la

Categories
Uncategorized

VMWare and Server 2008 R2 = Jumpy mouse

This is a known issue to VMware now and they are in the process of creating a new KB for the workaround.
 

Here is how to fix jumpy mouse for Windows 2008 R2:
 

After you install VMware Tools, reboot, login and your screen will be jumpy.
 

The VMware Tools install should have created the folder: C:/Program Files/Common Files/VMware/Drivers/wddm_video
 

browse to your Device Manager, choose your video adapter, right click, and "Update Driver". Browse to the folder listed above, reboot. At this point it should be fixed. If it is not fixed, shutdown your VM, go to edit settings, click on Video, and verify is has 8MB of Memory for Video. You may also need to verify this in the BIOS.

Categories
Linux

How to re-scan the SCSI bus on Linux

How to re-scan the SCSI bus on Linux.

echo "- – -" > /sys/class/scsi_host/host0/scan

Categories
VMWare

VMware console keyboard fix

In your user home, edit .vmware/config and add the following line:

xkeymap.nokeycodeMap = true

This should fix the key mapping problem…

Categories
Windows

Server 2008 profile deletion

I know we’ve all done this before.. Playing around with GPO’s, scripts or what have you and want to start out fresh so we delete the user profile directory under C:\Documents and Settings\<user name> to force the creation of a new profile directory. My colleague went to do that exact same thing on a Windows Server 2008 and that’s when I found out it’s not that easy on Server 2008.

After doing some searching I found this blog entry by Helge Klein.

It looks like Microsoft has now added a registry key that keeps track of the user profiles and their paths, among other things, and by deleting the directory alone you only solve half the issue and will get profile errors every time that user tries to log in. You will get the unable to load profile error and a new directory, usually C:\USERS\TEMP, will be created for that user.

If you have done this, the easiest way to do this is go to this reg key, 
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList
highlight each sub key until you find the "ProfileImagePath" that matches the one your deleted and then delete that key. I also found that you would have to reboot the server in order to complete this fix.

In future the best way to delete the profile is to go My Computer –> Properties –> Advanced System Settings –> User Profiles Settings and then delete the profile from there.

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

Enable SSH on ESXi

ESXi 3.5 does have SSH capablities but it is disabled and not supported by default. If you want to enable it, follow these steps:

  1. At the ESXi console press ALT-F1
  2. Type in "unsupported" and press Enter. You will not see the text as you type.
  3. You will see a Tech Support Mode warning and be prompted for the root password. Enter the root password and press enter
  4. Edit the inetd.conf file located at /etc/inetd.conf using VI
  5. Scroll down the file till you find the file that stares with #ssh, move the cursor over the # and press x
  6. Exit and Save by pressing ESC and typing :wq
  7. Type in "ps | grep inetd" and take note of the process ID
  8. Type in "kill -HUP <process ID from step 7>"
  9. You can now SSH in to the ESXi host

UPDATE: Confirmed to be working on ESXi 4.0 also

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