Linux Unix help !!

"Give respect to Time, One day at right Time, Time will respect You"

Tuesday, March 20, 2012

ConverT Shell Script to C - Binary [executable ]

Xxxxxxxxxxxxxx ConverT Shell Script to C - Binary [executable ] xxxxxxxxxxxxxxX

Hi many times we required to convert our script to be executable might be any of  below reasons .

- We don't want to share our script code
- We want to set suid, guid  that we can't do with shell scripts
- Want to run script without any extension as ./script.sh OR sh script.sh etc...

Here an fantastic toll that will hep you to achieve so .

Download & Install


Note: Install proper Linux/Unix flavor rpm and architecture else it will not going to work as expected

Download:
# cat /etc/redhat-release
Red Hat Enterprise Linux ES release 3 (Taroon)
# uname -i
i386

### So have downloaded right rpm for CentOS-6
# wget  http://pkgs.repoforge.org/shc/shc-3.8.6-1.el3.rf.i386.rpm

Install:
# cd   /rpms/shc/
# rpm -ivh shc-3.8.6-1.el3.rf.i386.rpm
warning: shc-3.8.6-1.el3.rf.i386.rpm: V3 DSA signature: NOKEY, key ID 6b8d79e6
Preparing...                ########################################### [100%]
   1:shc                    ########################################### [100%]


Write your script


AM taking example of   expire-date.sh

Convert to executable c binary
# cd  /myscripts; ls -lrt expire-date.sh
-rwxr-xr-x 1 root root 599 Mar 20 18:25 expire-date.sh

## Conver to exe using shc
# shc  -f  expire-date.sh
# gcc -o getexpiredt expire-pwd-date.sh.x.c
# mv getexpiredt  /bin/            <<-- As per your requirement

## Now test 
# file getexpiredt
getexpiredt: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, dynamically linked (uses shared libs), not stripped

## Execute
# getexpiredt
Enter Password Date [ DD:MM:YYYY EG: 25:02:2012] Format
                                                     DD: 01
                                                     MM: 02
                                                     YY: 2012
YOUR Password Will Expire on : Tue 1-May-2012
##

Have a fun ... Now remove your C code and sh code .
# rm -fr expire-pwd-date.sh*



--Shirish Shukla

convert shell script to c, c binary executable,shc -f cmd.sh command,linux, linuxva, shirish, shukla

2 comments:

Write Here .. your comments are always wellcome ..but no spam please !!

Followers

Pls LIKE my Story !!!