Thursday, October 11, 2012

How to write Control Character in Unix File

Open File in vi editor
Come in Insert mode by pressing Esc i
Press Control V
Then Press Control M
Then Esc


List of Ctrl Chars
 
Numeric Values Decimal Hex ASCII Character
Meaning Keyboard Entry
0
00
NUL Null Ctrl-@
1
01
SOH Start of heading
Ctrl-A
2
02
STX Start of text Ctrl-B
3
03
ETX Break/end of text Ctrl-C
4
04
EOT End of transmission Ctrl-D
5
05
ENQ Enquiry Ctrl-E
6
06
ACK Positive acknowledgment Ctrl-F
7
07
BEL Bell Ctrl-G
8
08
BS Backspace Ctrl-H
9
09
HT Horizontal tab Ctrl-I
10
0A
LF Line feed Ctrl-J
11
0B
VT Vertical tab Ctrl-K
12
0C
FF Form feed Ctrl-L
13
0D
CR Carriage return
(Equivilant to the Enter or
Return key)
Ctrl-M
14
0E
SO Shift out Ctrl-N
15
0F
SI Shift in/XON (resume
output)
Ctrl-O
16
10
DLE Data link escape Ctrl-P
17
11
DC1 Device control character 1 Ctrl-Q
18
12
DC2 Device control character 2
Ctrl-R
19
13
DC3 Device control character 3
Ctrl-S
20
14
DC4 Device control character 4
Ctrl-T
21
15
NAK Negative acknowledgment Ctrl-U
22
16
SYN Synchronous idle Ctrl-V
23
17
ETB End of transmission block Ctrl-W
24
18
CAN Cancel Ctrl-X
25
19
EM End of medium Ctrl-Y
26
1A
SUB Substitute/end of file Ctrl-Z
27
1B
ESC
Escape Ctrl-[
28
1C
FS File separator Ctrl-\
29
1D GS Group separator Ctrl-]
30
1E
RS
Record separator Ctrl-^
31
1F
US
Unit separator Ctrl-_

Monday, May 14, 2012

Secure SSH, CVS, SCP without Password Prompt

  1. Suppose the domain name of your server is server, and your login name loginname.
  2. On the client, generate a public and private key.

    ssh-keygen -C loginname@server -t dsa
     
    When asked for a password, simply press return. 
    The private key is stored in ~/.ssh/id_dsa, and the public key in ~/.ssh/id_dsa.pub.
    Never give the private key away! 
  3. Copy the public file to the server with

    scp ~/.ssh/id_dsa.pub loginname@server:~/
  4. Login on the server with 

    ssh loginname@server
     
    append the copied file to ~/.ssh/authorized_keys with
     
    cat ~/id_dsa.pub >>~/.ssh/authorized_keys
  5. If you want to enable this features on other servers, just repeat step 3 on each of the servers.

    
    That’s it! If you have done everything correctly, the next time you 
    login via SSH or use CVS over SSH, you will not need to enter a password
     yet you have a secure connenction.

    In case this does not work check /var/log/auth.log or /var/log/secure for error on server machine. If you see

    Authentication refused: bad ownership or modes for directory /home/dave/.ssh
     
    This is bcoz of bad permission these can be fixed with below commands.
     
    chmod g-w /home/your_user
    chmod 700 /home/your_user/.ssh
    chmod 600 /home/your_user/.ssh/authorized_keys

Thursday, March 22, 2012

Commands will let you determine which version(s) of GCC were used to compile and link a binary executable file

his trick will let you determine which version(s) of GCC were used to compile and link a binary executable file:
Code:
strings -a /path/to/binary-file | grep "GCC:" | sort -u

Here is a dirt-simple scripted version of the pipeline.
which-gcc:
#!/bin/bash

if [ -z "$1" ] ; then
echo "Usage: which-gcc file"
echo "Determines GCC version(s) used to build file"
exit
fi

strings -a $1 | grep "GCC:" | sort -u


Here are some examples from my system:
Code:
$ which-gcc /bin/bash
GCC: (GNU) 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)
I'm using GCC 3.4.6.

Code:
$ which-gcc `which vuescan`
GCC: (GNU) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
This commercial product was built on a Red Hat system, quite some time ago.

Code:
$ which-gcc /opt/google-earth/googleearth-bin
GCC: (GNU) 3.4.5 20050809 (prerelease) (Ubuntu 3.4.4-6ubuntu8)
GCC: (GNU) 4.0.2
The multiple version lines suggest Google Earth is at least in part statically linked. The final executable and at least one component library were built with different versions of GCC.

Code:
$ which-gcc /usr/bin/ooffice2

ooffice2 is not a GCC executable, thus no output. (It's a Bourne shell script. Reader exercise: produce a useful message when the file argument is not a GCC-created executable. :))

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