Friday, March 12, 2010

How to debug Linux scripts

I enjoy writing bash scripts as they will do a chunk of work for me within no time by just executing a single command.

But to make my script perform requested operation, many a times i need to debug it and make it work proper.

1) To debug a script use below command
$bash -x ./my_script.sh


2) To debug only part of a script use set -x and set +x at start and end of code snippet.
Ex:
$vim my_script.sh

#!/bin/bash
...
...
set -x
...
...
set +x
....

#./my_script.sh

3) In script, one can always use "echo" before any particular command to watch its contents.

Tuesday, March 9, 2010

How to access remote host applications.

How to run X(gedit, meld, eclipse etc.,) applications in the remote session and have them display their windows on your PC.

This is how one can achieve it:

a) First add remote ipaddr to ur server access control program using xhost.
$xhost +192.168.1.14 (remote m/c ipaddr)

b) Login to remote m/c using "-X" flag
$ssh -X user@192.168.1.14

c) u r done, just execute any command & have fun
$gedit

Note:This will work from ur linux box or tools like Xmanager etc.,
But if u want ur putty to do this work for u, then follow this link "How to configue putty to access X applications".