Friday, September 2, 2011

how to write a linux command wrapper

In case if you want to extend the command functionality we can write a wrapper over standard linux command. We can achieve this through bash script and it is simpler.

Here is the example for it:

rdesktop is an linux command which is used to connect windows machine.

rdesktop -f [remote-machine-address] is the basic command to connect to windows machine.

Now if you want to enhance it to support extra options we can use the following options:
rdesktop -r sound:local -r clipboard:PRIMARYCLIPBOARD -r disk:root=/

sound:local -- to enable sound redirection.
clipboard:PRIMARYCLIPBOARD -- To allow copy/paste between rdesktop & host machine.
disk:root=/ -- To share my root directory with remote machine.

mv /usr/bin/rdesktop /usr/bin/rdesktop.bin

Create a file called /usr/bin/rdesktop.wrapper and add this to the file.

#!/bin/bash

/usr/bin/rdesktop.bin -r sound:local -r clipboard -r disk:root=/ $*
## EOF

Make the file executable.
chmod +x /usr/bin/rdesktop.wrapper

Then create a symbolic link to the wrapper.
ln -s /usr/bin/rdesktop.wrapper /usr/bin/rdesktop


You can achieve the same effect through "alias" option in bash but we(I) can use the example as starting point for shell scripting :-)


Reference:
http://blog.offenders.org/?p=85

No comments:

Post a Comment