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

 

Categories
Exchange

How to Authenticate to SMTP server via Command Line

Recently I had to prove to an application admin that the user he was using to send SMTP email was able to authenticate and properly send email via SMTP. The easiest way to prove that this was a configuration issue with the application and not a SMTP issue was to do it from the server via command line.

Steps to send SMTP email and authenticate:

Telnet to server on port 25

telnet servername 25

Type EHLO

EHLO
250-servername.domain.com Hello [10.149.1.55]
250-TURN
250-SIZE
250-ETRN
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-8bitmime
250-BINARYMIME
250-CHUNKING
250-VRFY
250-X-EXPS GSSAPI NTLM LOGIN
250-X-EXPS=LOGIN
250-AUTH GSSAPI NTLM LOGIN
250-AUTH=LOGIN
250-X-LINK2STATE
250-XEXCH50
250 OK

This is were it got interesting. It seems that an SMTP server asks and expects answers in Base64. For example, "VXNlcm5hbWU6" in Base64 means "Username:" and "UGFzc3dvcmQ6" means "Password:"
You can find a few Base64 encoders/decoders on the need just by googling it, I used makcoder.sourceforge.net/demo/base64.php.

So in order to authenticate to the SMTP server you will need to encode the username and password to Base64:
"Username" = "VXNlcm5hbWU="
"Password" = "UGFzc3dvcmQ="

Now to auth to the server:

Type AUTH login

AUTH login
334 VXNlcm5hbWU6

Enter the Base64 username and press enter:

VXNlcm5hbWU=

Next enter the Base64 password followed by enter

334 UGFzc3dvcmQ6
UGFzc3dvcmQ=
235 2.7.0 Authentication successful.

This shows that the user was able to authenticate and then all that’s next is to send a test email and then confirm that the mailbox recieved it

MAIL FROM: username@domain.com
250 2.1.0 username@domain.com….Sender OK
RCPT TO: username@domain.com
250 2.1.5 username@domain.com
DATA
354 Start mail input; end with <CRLF>.<CRLF>
This is a test SMTP email from application server
.
250 2.6.0 <servernameLrLySMy00000002@servername.domain.com> Queued mail for delivery

Categories
Freebsd

Passwordless ssh login with keys

Create a key with no passphrase on the source machine

[install@source ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/install/.ssh/id_rsa):
Created directory ‘/home/install/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/install/.ssh/id_rsa.
Your public key has been saved in /home/install/.ssh/id_rsa.pub.
The key fingerprint is:
66:c1:3f:95:c6:a9:d6:99:49:bf:a0:57:4f:a3:78:49 install@localhost.localdomain

Copy it to the destination machine…

[install@source ~]$ scp id_rsa.pub 10.50.2.50:~

On the destination machine create the .ssh directory and copy the id_rsa.pub to authorized_keys. If you have multiple keys you can just append it, something like this “cat id_rsa.pub >> authorized_keys”

[install@destination ~]$ mkdir .ssh
[install@destination ~]$ chmod 700 .ssh
[install@destination ~]$ cp id_rsa.pub .ssh/authorized_keys

Now you should be able to login…

[install@source .ssh]$ ssh 10.50.2.50
Last login: Fri Sep  5 14:18:01 2008 from 10.50.2.51
[install@destination ~]$

Categories
Openbsd

Creating a memory leak on Linux/Unix

I recently had to create a memory leak to do some testing, here is a snippet of code that I used to create a leak. You can adjust malloc size to allocate more memory, or adjust the usleep to adjust how aggressive it is. the code below on a machine with 500M of memory would chew up about 1% memory a second. Enjoy!

#include <stdlib.h>
#include <unistd.h>

int main(void) {
    /* An infinite loop. */
    while (1) {
       /* Try to allocate some memory. */
       malloc(8386080);
       /* sleep for a bit so its not so aggressive */
       usleep(10000);
    }
    return EXIT_SUCCESS;
}

Categories
Linux

Grant Shell access (SSH) to Root on ESX 3.5 update 2

If you’d like to allow shell access to the root account on ESX 3.5 Update 2 you need to modify the sshd_config file.

  1. Login into the console using the root account
  2. Edit the sshd_config file
     

    vi /etc/ssh/sshd_config

  3. Find "PermitRootLogin no" and change to "PermitRootLogin yes"
  4. Restart the sshd server
     

    service sshd restart

Categories
Vista

Turn off DEP on Windows Vista and NO BOOT.INI

If your used to turning DEP off completely on Windows XP you’ll have a hard time doing it on Vista.

The BOOT.INI file that is in Windows XP is now gone in Vista so you can’t just edit it to turn off DEP.

Windows Vista now comes with a command line tool called BCDEDIT.EXE that will edit the boot configs for you. It’s actually easier then editing the BOOT.INI file but only if you know the command to do it.

So here’s the command, make sure you run in with elevated priviledges.

Turn OFF DEP:
 

bcdedit.exe /set {current} nx AlwaysOff

Turn ON DEP:
 

bcdedit.exe /set {current} nx AlwaysOn

 

Categories
Openbsd

wget through proxy tutorial

Ok so I had an issue using wget from the cmd line on my linux box, so here is how to get a proxy to work with wget:

First off export a variable called "http_proxy":

export http_proxy=192.168.1.2

This will try to get to your proxy via port 80, you could also specify like this(if you are on another port):

export http_proxy=192.168.1.2:8080

Then connect specifying your auth creds if you need to pass any:

wget –proxy-user=myusername –proxy-password=mypassword http://www.myserver.com/download/strace-4.5.15-1.el5.x86_64.rpm

 

And you should be good to go!

Categories
Windows

Convert accountExpires attribute in AD to date

If you’ve ever exported the accountExpires attribute from AD you’ll notice that it’s an 64-bit number. It represents the number of 100-nanosecond intervals since 12:00 AM January 1, 1601 in UTC. What this means is that it’s practically impossible to read unless your a math genius. 😉

Here is a quick VBS script that will take that number and convert it to a real date:

Dim WshShell, oExec, objArgs, exe, work
Set WshShell = CreateObject("WScript.Shell")
Set objArgs = Wscript.Arguments
if objArgs.count = 0 Then
Wscript.Echo "FileTime argument required"
Wscript.Quit
end If
exe = "w32tm.exe /ntte " & objArgs(0)
set oExec = WshShell.Exec(exe)
Do While oExec.Status = 0
WScript.Sleep 100
Loop
work = Split(oExec.StdOut.Read(60))
Wscript.Echo work(3) & " " & work(4)

Just copy and paste this into notepad and save as finddate.vbs. Then just run "finddate.vbs <accountExpires value>"

Finddate.vbs 128674944000000000

Would result in this pop up:

date.jpg