Tuesday, May 10, 2011

How to check directory/file exists in shell script

Check file exists code snippet

FILE_TO_CHECK="/path/to/myfile"


if [-f $FILE_TO_CHECK]; then 
......
do something here
......
fi 


Check directory exists code snippet

DIR_TO_CHECK="/path/to/my/dir"

if [-d $DIR_TO_CHECK]; then 
......
do something here
......
fi 



Thursday, June 17, 2010

Transfer file using SCP as a background process

I wanted to upload my ear to a remote UAT box before
leaving  from office.I got a way to do so from
markus.revti.com

$ scp file/to/upload username@hostname:/remote/file/path 2>&1

System will as for system password for the remote host ,
after entering the password,do CTRL+Z

which will show Stoped(1) .......

then type

[$] bg

which will run the process in background.




Wednesday, June 16, 2010

How to connect to MSSQL from Linux using ODBC

Following steps has been tested in CentOS 5 and Redhat Enterprise Server

To connect to MSSQL 2005 server from linux machine,unixODBC and freeTDS packages has to be installed.

[$] yum list unixODBC*
Loaded plugins: downloadonly, rhnplugin, security
Excluding Packages in global exclude list
Finished
Available Packages
unixODBC.i386 2.2.11-7.1
unixODBC-devel.i386 2.2.11-7.1
unixODBC-kde.i386 2.2.11-7.1

Install following packages

[$] yum install unixODBC.i386
[$] yum install unixODBC-devel.i386

Once ODBC has been installed,install FreeTDS

[$] yum list freetds*
Loaded plugins: downloadonly, rhnplugin, security
Excluding Packages in global exclude list
Finished
Available Packages
freetds.i386 0.64-1.1.rs
freetds-unixodbc.i386 0.64-1.1.rs
freetds-devel.i386 0.64-1.1.rs
freetds-doc.i386 0.64-1.1.rs
[$] yum install freetds.i386
[$] yum install reetds-unixodbc.i386

Once you have completed installation

Edit /etc/odbc.ini file by adding a DNS configuration as shown below(Create a new file if it doesn't exists).

[MSSQLDB]
Driver = FreeTDS
Description = MS SQL DNS
Trace = Yes
TraceFile = /var/log/mstest.log
Servername = MSSQLDB_SERVER
Database =
Port = 1433

Open /etc/odbcinst.ini file and confirm that driver configuration for FreeTDS exists otherwise add following entry

[FreeTDS]
Description = FreeTDS unixODBC Driver
Driver = /usr/lib/libtdsodbc.so.0
Setup = /usr/lib/libtdsodbc.so.0
UsageCount = 2

Please not that the name FreeTDS has been refered in /etc/odbc.ini file as Driver

Now we have to configure Free TDS with host and port number of the database.To do that edit /etc/freetds.conf

[MSSQLDB_SERVER]
host =
port = 1433
tds version = 8.0

Please not that the name MSSQLDB_SERVER has been refered in /etc/odbc.ini file as Servername.

Now we are done with configuration.To check the connection try

[$] isql MSSQLDB  

above command should give following result if you could connect to MSSQL server successfully

+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>

References

FreeTDS

UnixODBC