Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Thursday, July 19, 2012

Subversion and Shell Script : ^M character

The next assignment was to put all shell scripts, perl scripts and data files under source control and obviously subversion was my choice as we are using the same for source control of application code base.

Everything went smooth initially but we ran into issues while executing shell scripts post svn update on UNIX box. It was quite clear that EOL character introduced while editing our files in Windows development environment converts into the infamous ^M character.

Removing these characters using dos2unix or stripping the character via VI editor using find and replace were not functional solutions in the long run; so I started searching again for something which might be of help in this case and eventually got to the Solution

The subversion properties are a neat solution to such issues; just set the repository property svn:eol-style as native and let subversion maintain the EOF characters by itself.

The newlines of Windows will never be ^M of UNIX.

Thursday, February 23, 2012

Environment Friendly Cron Shell Scripts

You created a neat shell script which makes use of some environment variables and all the tests went successful. But as soon as the script is scheduled in crontab; none of the environment variables were recognized and script fails.

Since crontab is executed as a different user in UNIX so assuming that your environment variables defined in $HOME/.profile will be available to any other user is wrong.

A simple solution is to execute the environment variables at the beginning, just after where you define the shell, of the script:

example:
#!bin/bash
. /home/user/.profile


where /home/user is the absolute path of your $HOME variable.

This should get you going.

TIP: Also using following export and assignation in a single line causes issues with shell scripts so make sure that
export MY_VAR=MY_VALUE
is replaced by
MY_VAR=MY_VALUE
export MY_VAR


Otherwise errors in your .profile file may cause issues with your shell script. All the best!!!