Pages

Saturday, April 25, 2009

Ubuntu Tricks: Compile, Run or be Executed

There will be instances that you may need to protect your shell script contents from being read, such as for instance if they contained log-in or other account details and you wanted to share the script for automation. I was able to find a simple tool that could do this, shc.

Its not part of the usual distribution, so you'll need to have this installed via the package manager or via the terminal using apt-get:
sudo apt-get install shc

After which, simple call the function using this format: shc -f
Example: shc -f mydownloads.sh

What shc does is translate your script into C, then compile it and make it executable. If we ran the example this will result in two-(2) additional files: source and executable
Example:
-rw-r--r-- 1 me me 354 2009-04-25 13:11 mydownloads.sh
-rwx--x--x 1 me me 10948 2009-04-25 13:11 mydownloads.sh.x
-rw-r--r-- 1 me me 11299 2009-04-25 13:11 mydownloads.sh.x.c

The file mydownloads.sh.x is automatically set as executable. Make sure to test it and compare the results with the original script. In my tests you can even ranema the file to something else more descriptive.

But what if in your changing and sharing the executable bit gets unset? Well, that is simple. Just run chmod.

sudo chmod +x

In the example above you'll see the bit permission change from
-rw------- to -rwx--x--x.


No comments:

Post a Comment