Tech Blog

Dealing with ORA-12169(service name too long) with
Oracle Instant Client on Mac OS X

September 22nd, 2011

Running Oracle Instant Client and related SQL*Plus on Mac OS X, with tnsnames.ora created and environment variables setup correctly was causing this error repeatedly, not allowing login into the database via “sqlplus” from a terminal/command line.

ORA-12169: TNS:Net service name given as connect identifier is too long

The tnsnames.ora file was good, and there was nothing unusual about the “service_name” used in the TNS entries. So this error was a bit surprising.

The reason was simple, the tnsnames.ora file had Windows encoding (CR/LF) instead of Unix/Linux encoding (just LF). Just saving the tnsnames.ora file in *nix format solved the problem !

Hope that this information is useful to others.

Ensuring only instance of shell script execution

May 25th, 2011

Shell scripts are often used as the glue to put various pieces together, and in automation of tasks (especially in the *nix world). Whether it is to ensure that any failures in processes are notified to support teams, or to marry ETL processes from tools like AbInitio or Informatica to perl code, shell scripts play an important and routine role, especially in *nix environments like Linux.

One of the common requirements in the shell scripting world is to ensure that two copies of the same script does not run at the same time. Whether kicked off accidentally, or because the earlier invocation took abnormally long to complete, in most cases the requirement is to have only one copy of a script executing at any given time. If a new copy gets kicked off, it should notice that another copy is running, and exit. It is also a requirement that the script be able to survive unplanned events like server restarts

Here is a Linux based version we have been using, that has been enhanced to use the “parent process id” also, as compared to the simple technique of just using the “process id” alone (which can generate false positives).

# lock file location
export LOCK_FILE=/var/run/my_process_name.lock

# check if another copy is running
if [[ -a $LOCK_FILE ]]; then
	pid=$(cat $LOCK_FILE | awk '{print $1}')
	ppid=$(cat $LOCK_FILE | awk '{print $2}')
	# validate contents of previous lock file
	if (( $vpid < 2 || $vppid < 2 )); then
		echo "Corrupt lock file $LOCK_FILE ... Exiting"
		cp -f $LOCK_FILE ${LOCK_FILE}.`date +%Y%m%d%H%M%S`
	# check if ppid matches pid
	ps -f -p $pid --no-headers | grep $ppid >/dev/null 2>&1
	if [[ $? -eq 0 ]]; then
		echo "Another copy of script running with process id $pid"
		echo "Bogus lock file found, removing"
		rm -f $LOCK_FILE >/dev/null
ps -f -p $pid --no-headers | awk '{print $2,$3}' > $LOCK_FILE
echo "Starting with process id $pid"

This piece of code needs to go at the beginning of what ever script you want to prevent from having multiple copies running simultaneously. If you are not in Linux, minor tweaks may be needed.


Systalent, “Thapasya”, InfoPark
Kochi 682030, Kerala, India

  • India (+91) 484 241 5230
  • USA (+1) 512 853 9870
  • Qatar (+974) 55600565


Systalent becomes an extension of your development team. All phases of development are tracked and controlled using industry standard tools and practices. We also help reduce your IT costs by leveraging open-source technologies where appropriate.

Untitled Document