Thursday, September 15, 2011

Restore Grub of Installed Linux

I have machine with dual boot. 4 years back I installed Windows XP Pro and Ubuntu 7.10. After 4 years it was time to reinstall XP the only issue was restoring GRUB as on Ubuntu 7.10 back to MBR as XP will rewrite the MBR. Here are the steps to achieve it.

After successful re-installation of XP.
  • Boot system with Live CD of Linux can be ubuntu/Knnopix etc.
  • mount the Linux Partition after Live CD is done.
    sudo mkdir /mnt/root
    sudo mount -t etx3 /dev/sda6 /mnt/root
  • Then have to mount the proc subsystem and dev inside /mnt/root
    sudo mount -t proc none /mnt/root/proc
    sudo mount -o bind /dev /mnt/root/dev
  • Doing this allows grub to discover drives.
  • Now time to run grub
    sudo chroot /mnt/root grub
    find /boot/grub/stage1
  • I had (hd0,5)
    root (hd0,5)
    setup (hd0)
  • Thats it. Grub is now restored on MBR.

Wednesday, July 07, 2010

Directory List in Text File under Windows

It very simple...just try below command


dir /AD /S /B > C:\DirList.txt


check C:\DirList.txt it will have the complete directory list under root directory passed.

Thursday, May 27, 2010

Date datatype does not display time when selected

Default date format is set to DD-MON-YY. This can be changed by running below sql.

alter session set nls_date_format = 'dd/mm/yyyy hh24:mi:ss';

Tuesday, May 11, 2010

SQL Server 2005 Express and 2008 Express Side by Side

Normally this fails due to - The SQL Server 2005 Express Tools are installed i.e. SQL Server 2005 Management Studio....There are two ways of fixing it...

a) Remove 2005 Management Studio...and then try to Install SQL Server 2008 Express Edition..I have not tried this as I wanted both Management Studion i.e 2005 and 2008...Needless to say 2008 Management Studio can access SQL Server 2005 Database.

b) While installing SQL Server 2008 Express it checks for Registry Key HKLM/SOFTWARE\Microsoft\Microsoft SQL Server\90\Tools\ShellSEM....rename this key from ShellSEM to ShellSEM.old. Install SQL Server 2008 Express...after installation name it back to ShellSEM...now both Management Studio will be in working state...

Saturday, February 28, 2009

Compile GCC in Loonix / HP-UX


export INSTALLATION_GCC=/home/lalit/gccinstall
echo $INSTALLATION_GCC
export srcdir=$INSTALLATION_GCC/gcc-3.2
echo $srcdir
export objdir=$INSTALLATION_GCC/gcc-bin
echo $objdir
$srcdir/configure \
--enable-languages=c,c++ \
--enable-threads=posix \
--with-gnu-as \
--with-gnu-ld

gmake bootstrap-lean

Friday, January 16, 2009

Using sed to remove leading or trailing spaces

Remove leading or trailing spaces from file
sed -e "s/[ ]*//g" 1.xml > 2.xml
For with in tags like in XML
sed -e "s/[ ]*<\//<\//g" 1.xml > 2.xml

Thursday, September 04, 2008

CVS Client commands for Linux

To Checkout Code

export CVS_RSH=ssh
cvs -z9 -d :ext:<user>@<cvsserver>:<repository> co <module name>

Thursday, August 07, 2008

Deployment of Applications Built with VC++ 2005

Deploying applications built with VC++ 2005 requires presence of particular libraries needed by Visual C++. This will also vary according to the target machine's operating system.

There are several options for the deployment:

  1. Use Visual C++ Redistributable Package
  2. Use the MSM merge modules
  3. Use Private Assembly



While the first two options respectfully require full installation of all libraries and presence of WinSxS assemblies (not present under all currently used operating systems), the third one can be used by copying only required libraries in the application directory. Furthermore, option 1) and 2) require administrative privileges.

The following libraries are required for option 3):

DLL Visual C++ Library
atl90.dll C Runtime and Standard C++ Libraries
msvcm90.dll
msvcp90.dll
msvcr90.dll
C Runtime and Standard C++ Libraries
mfc90.dll
mfc90u.dll
mfcm90.dll
mfcm90u.dll
mfcmifc90.dll
Microsoft Foundation Classes

Thursday, July 17, 2008

Lua - Scripting Language

More info on Lua available at About - Lua.

Here we will see how we can call lua script from C++. Code below is tested with VC2K5 EE with Lua 5.1.

#include

extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}

class Lua_State
{
lua_State *L;
public:
Lua_State() : L(lua_open()) { }

~Lua_State() {
lua_close(L);
}

// implicitly act as a lua_State pointer
inline operator lua_State*() {
return L;
}
};

static void open_libs(lua_State *L)
{
luaL_openlibs(L); // Lua 5.1 single call to load all libs
}

static int execute_program(lua_State *L)
{
// make a short function to make program behaviour more clear
return lua_pcall(L, 0, LUA_MULTRET, 0);
}

static void report_errors(lua_State *L, const int status)
{
if ( status!=0 ) {
std::cerr << "-- " << lua_tostring(L, -1) << std::endl;
lua_pop(L, 1); // remove error message
}
}

int main(int argc, char** argv)
{
for ( int n=1; n
Lua_State L;
open_libs(L);

int s = luaL_loadfile(L, argv[n]);

if ( s==0 )
s = execute_program(L);

report_errors(L, s);

// lua_close(L) automatically called here
}

int i;
std::cin >> i;
return 0;
}


Additional library required to build is luaX.Y.lib where X and Y refers to lua version. I had this as lua5.1.lib.

This is the simple way to use/call lua from C++. More useful/handy examples available at SampleCode.

Friday, December 21, 2007

How does one truncate a transaction log file in MS SQL

BACKUP LOG <DB NAME> WITH TRUNCATE_ONLY
USE <DB NAME>
DBCC SHRINKFILE (<Log Logical Name>, 20) -- where 20 = 20 MB

How Drop Tablespace and Recover Oracle Database When Accidentally Delete Datafile

The solution to the missing datafiles is to drop the affected tablespace where has incomplete datafiles, and then recreate the tablespace and import the data into the tablespace from backup. However, the steps are not so straight forward.


  • Run SQL*Plus.

  • Connect to database as SYSDBA with this query:
    CONNECT / AS SYSDBA

  • Mount the database instead of starting it up: 
    STARTUP MOUNT;

  • Issue the following command to bring the missing datafile offline so that Oracle won’t trying to connect and access the datafile anymore:
    ALTER DATABASE DATAFILE '<datafile name with complete path>' OFFLINE DROP;

    Repeat the command for every datafiles that unaccounted for.

  • Now start the database proper:
    ALTER DATABASE OPEN;

  • As the tablespace has damaged, drop it to recreate from fresh backup.
    DROP TABLESPACE <tablespace name> INCLUDING CONTENTS;

  • Ensure the other datafiles for the tablespace has been deleted, if not, remove them manually from the operating system.

  • Continue with the recovery process.

  • More Info

Tuesday, December 18, 2007

Deleting files in tar file

To Delete file from tar file
tar --delete --file=<tarfile> <file name>

To Delete file using wildcards from tar file
tar --wildcards --delete --file=<tarfile> <file name>

To Delete specific file from tar file
tar --delete --file=<tarfile> <path/to/that/file/in/tarfile/filename>

Friday, November 23, 2007

Making Micrphone work in Ubuntu 7.04

Assuming all the drivers and other things are in place.
Please look at these links for that

Debugging Sound Problems

In case all look ok do this.
a) Open terminal
b) type 'alsamixer'
c) Use left right arrow keys to select and up and down to adjust.
d) Adjust, Front Mic, Mic Boost and Input Source.
e) Select tab and adjust Front Mic, Mic Boost and Capture.
f) Press esc to quit.

Try skype or other recording tools to test.

Gud Luck.

More Info here
How TO: Getting Microphone to work

Monday, September 10, 2007

HPUX Mem Info C Code

/*
* @(#)$Header: memdetail.c,v 1.1 2001/05/03 15:35:00 nsr1521 Exp $
*
* determine detailed current memory utilized and print.
*
* No warranty is expressed or implied.
* Your mileage may vary.
*
* Contact: srobertson@bcbs-ga.com
*
*/

static char ident[] = "@(#)$Revision: 1.1 $";

#define KB 1024

#include <unistd.h>
#include <sys/param.h>
#include <sys/pstat.h>

main() {
struct pst_static sbuf;
struct pst_dynamic dbuf;
struct pst_vminfo vbuf;
double page_size, sys_mem;
double phys_mem, used_phys_mem, avail_mem;
double total_virtual_mem, active_virtual_mem, avail_virtual_mem;
double total_real_mem, active_real_mem, avail_real_mem;
double total_swap_dev, used_swap_dev, avail_swap_dev;
double total_swap_mem, used_swap_mem, avail_swap_mem;

/* get static information about the system */
if (pstat_getstatic(&sbuf, sizeof(sbuf), (size_t)1, 0) != -1)
{
phys_mem = sbuf.physical_memory;
page_size = sbuf.page_size;
}
else
perror("pstat_getstatic()");

/* get dynamic information about the system */
if (pstat_getdynamic(&dbuf, sizeof(dbuf), (size_t)1, 0) != -1)

{
avail_mem = dbuf.psd_free;
total_virtual_mem = dbuf.psd_vm;
active_virtual_mem = dbuf.psd_avm;
total_real_mem = dbuf.psd_rm;
active_real_mem = dbuf.psd_arm;
}
else
perror("pstat_getdynamic()");

/* get VM information about the system */
if (pstat_getvminfo(&vbuf, sizeof(vbuf), (size_t)1, 0) != -1)
{
sys_mem = vbuf.psv_sysmem;
total_swap_dev = vbuf.psv_swapspc_max;
avail_swap_dev = vbuf.psv_swapspc_cnt;
total_swap_mem = vbuf.psv_swapmem_max;
avail_swap_mem = vbuf.psv_swapmem_cnt;
}
else
perror("pstat_getvminfo()");

/* calculate used physical memory */
used_phys_mem = phys_mem - avail_mem;
/* calculate avail virtual memory */
avail_virtual_mem = total_virtual_mem - active_virtual_mem;
/* calculate avail real memory */
avail_real_mem = total_real_mem - active_real_mem;
/* calculate used swap on device */
used_swap_dev = total_swap_dev - avail_swap_dev;
/* calculate used swap on memory */
used_swap_mem = total_swap_mem - avail_swap_mem;

(void)printf("%-15s\t%6s\t%6s\t%6s\t%6s\n",
"Memory Stat","total","used","avail","%used");

(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"physical",
(phys_mem * page_size) / (KB * KB),
(used_phys_mem * page_size) / (KB * KB),
(avail_mem * page_size) / (KB * KB),
used_phys_mem * 100 / phys_mem);

(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"active virtual",
(total_virtual_mem * page_size) / (KB * KB),
(active_virtual_mem * page_size) / (KB * KB),
(avail_virtual_mem * page_size) / (KB * KB),
active_virtual_mem * 100 / total_virtual_mem);

(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"active real",
(total_real_mem * page_size) / (KB * KB),
(active_real_mem * page_size) / (KB * KB),
(avail_real_mem * page_size) / (KB * KB),
active_real_mem * 100 / total_real_mem);

(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"memory swap",
(total_swap_mem * page_size) / (KB * KB),
(used_swap_mem * page_size) / (KB * KB),
(avail_swap_mem * page_size) / (KB * KB),
used_swap_mem * 100 / total_swap_mem);

(void)printf("%-15s\t%6.1f\t%6.1f\t%6.1f\t%5.0f%%\n",
"device swap",
(total_swap_dev * page_size) / (KB * KB),
(used_swap_dev * page_size) / (KB * KB),
(avail_swap_dev * page_size) / (KB * KB),
used_swap_dev * 100 / total_swap_dev);

return;
}

Wednesday, September 05, 2007

Linux Process and System Memory Info

FILENAME="/opt/apal3/SystemInfo/SystemInfo.txt"

PIDINDEX="4"
APAL3BIN="apal3_test3"

EXECUTION_DATE=`date +%Y%m%d%H%M%S`
echo $EXECUTION_DATE >> $FILENAME
echo "==============" >> $FILENAME

echo "System Mem Info : " >> $FILENAME
echo "==================" >> $FILENAME
cat /proc/meminfo >> $FILENAME
echo >> $FILENAME

echo "System Memory Info : " >> $FILENAME
echo "=====================" >> $FILENAME
free -mto >> $FILENAME
echo >> $FILENAME

echo "System Swap Info : " >> $FILENAME
echo "===================" >> $FILENAME
cat /proc/swaps >> $FILENAME
echo >> $FILENAME

echo "APAL5 Process Info : " >> $FILENAME
echo "====================" >> $FILENAME
APAL3_PID=`ps -ale | grep [" "]$APAL3BIN$ | tr -s " " | cut -f $PIDINDEX -d " "`
echo "APAL3_PID : "$APAL3_PID >> $FILENAME
cat /proc/$APAL3_PID/status >> $FILENAME
echo >> $FILENAME

echo "APAL5 Thread Info : " >> $FILENAME
echo "====================" >> $FILENAME
ps -eLf | grep $APAL3_PID >> $FILENAME
echo >> $FILENAME

echo "Kernel Message : " >> $FILENAME
echo "=================" >> $FILENAME
dmesg | grep -n kernel >> $FILENAME

echo "************************************************************" >> $FILENAME
echo >> $FILENAME

Tuesday, September 04, 2007

Max threads per process

In Linux

To view
cat /proc/sys/kernel/threads-max

To Edit
echo > /proc/sys/kernel/threads-max

Tuesday, July 24, 2007

GCC 4.1.2 GCC 4.1.2 Install Intructions

GCC 4.1.2 GCC 4.1.2 Install Intructions
http://hpux.cs.utah.edu/hppd/cgi-bin/wwwtar?
/hpux/Gnu/gcc-4.1.2/gcc-4.1.2-src-11.11.tar.gz+gcc-4.1.2/
HPUX.Install+text

ANSI C patches details
http://hpux.connect.org.uk/hppd/answers/4-4.html

Tuesday, June 26, 2007

Adding .flv MIME type in IIS

1) Select the site to configure in IIS, right click and select "Properties"
2) Under HTTP Headers Tab, select "File Types" under the MIME Map section and select "New Type"
3) Type ".flv" as the associated extension and "video/x-flv" as the content type.
4) Select "OK" and you're ready to fly!

Tuesday, June 19, 2007

Oracle 9i Install Guide for Linux (Ubuntu 7.04) - 32bit

Oracle 9i Install Guide for Linux (Ubuntu 7.04) - 32bit


Pre Install Steps

1) Get JRE 1.3.1 (jre1.3.1_20)
1.a) Install this at /opt/jre1.3.1_20
1.b) cd /opt/jre1.3.1_20/bin
1.c) ln -s java jre
1.d) cd /opt/jre1.3.1_20/bin/i386/native_threads
1.e) ln -s java jre

2) Apply patch for Oracle 9i
2.a) unzip p3006854_ 9204_LINUX.zip
2.b) cd 3006854
2.c) sudo sh rhel3_pre_install.sh

3) Set Kernel Parameters
3.a) sudo vim /etc/sysctl.conf
3.b) Add -
kernel.sem = 250 32000 100 128
kernel.shmmax = 2147483648
kernel.shmmni = 128
kernel.shmall = 2097152
kernel.msgmnb = 65536
kernel.msgmni = 2878
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 6500
3.c) execute "sysctl -p" or reboot system to apply above settings

4) Create Oracle account
4.a) groupadd dba
4.b) usradd -g dba oracle

5) Setting Oracle Enviroment *
5.a) sudo mkdir /u01
5.b) sudo mkdir /u01/app
5.c) sudo mkdir /u01/app/oracle
5.d) sudo chown oracle:dba /u01/app/oracle
5.e) sudo vim /etc/profile
5.f) ORACLE_BASE=/u01/app/oracle
ORACLE_SID=WOORAU
export ORACLE_BASE ORACLE_SID
ORACLE_HOME=/home/oracle/OraHome1
export ORACLE_HOME

export PATH:$PATH:$ORACLE_HOME/bin

6) Get Oracle 9i from www.oracle.com
6.a) Login as user oracle
6.b) mkdir Oracle9i
6.c) cd Oracle9i
6.d) Copy all the 3 files here as downloaded
6.e) gunzip ship_9204_linux_disk1.cpio.gz
6.f) gunzip ship_9204_linux_disk2.cpio.gz
6.g) gunzip ship_9204_linux_disk3.cpio.gz
6.h) cpio -idmv <>7) Fix JRE PATH
7.a) sudo vim Disk1/install/linux/oraparam.ini
7.b) JRE_LOCATION=/opt/jre1.3.1_20

8) Run Installer
8.a) ./runInstaller
8.b) edit the JRE_LOCATION setting in the $ORACLE_BASE/oui/oraparam.ini
sudo vim $ORACLE_BASE/oui/oraparam.ini
8.c) JRE_LOCATION=/opt/jre1.3.1_20

Post Install

9) Creating Listner and Database
Installer will create Listener, Database and set Apache server. In case this is not done at that tim we can use these tools to achieve the same.
9.a) For Database use dbca tool in $ORACLE_HOME/bin.
9.b) For creating Listner and Local Service use netca in $ORACLE_HOME/bin.

10) Start and stop script.
10.a) Oracle start script
sqlplus /nolog <<>

* - Additional Settings Fedora Core 2,3,4 only

LD_ASSUME_KERNEL=2.4.1
THREADS_FLAG=native

Note -

In case of error while running runInstaller edit it and change

if [[ ($RHVER = $Check1) || ($RHVER = $Check2) ]];
then
export LD_ASSUME_KERNEL=2.4.19
fi

to

#if [[ ($RHVER = $Check1) || ($RHVER = $Check2) ]];
#then
# export LD_ASSUME_KERNEL=2.4.19
#fi

VCEESetup

Note: If you are using Microsoft Visual Studio Professional, there is no need to apply any of the steps listed below.

The following install packages are required:


ISO IMG
Microsoft Visual C++ 2005 Express Edition download download
Microsoft ® Windows Server® 2003 R2 Platform SDK download download

Steps:

1. Microsoft VCEE

1.1. Install Microsoft Visual C++ 2005 Express Edition

1.2. Start the IDE and follow the instructions from the start page.

2. Platform SDK

2.1. Install Microsoft Windows Server 2003 R2 Platform SDK

2.2. Follow the instructions to add your source, include and library paths (Tools->Options->Projects and Solutions->VC++ Directories) and modify corewin_express.vsprops file.

2.3. Add the additional include directory : $(platformsdkdir)\\Include\\atl, where $(platformsdkdir) is where your SDK is installed. You can set an environment variable in vsvars32.bat to reflect that.

2.4. Modify the following in the atlbase.h (the file should reside in $(platformsdkdir)\\Include\\)

Starting at line 287 in the original file:

/*
PVOID __stdcall __AllocStdCallThunk(VOID);
VOID __stdcall __FreeStdCallThunk(PVOID);

#define AllocStdCallThunk() __AllocStdCallThunk()
#define FreeStdCallThunk(p) __FreeStdCallThunk(p)

#pragma comment(lib, "atlthunk.lib")
*/

#define AllocStdCallThunk() HeapAlloc(GetProcessHeap(), 0, sizeof(_stdcallthunk))
#define FreeStdCallThunk(p) HeapFree(GetProcessHeap(), 0, p)

2.5. It is a very good idea to try to create and build a simple Win32 project in order to verify that all the modifications undertaken are in place.


3. Service Packs

3.1. Download Visual C++ 2005 Express SP1