Saturday, January 19, 2013

How to install and use SHC (Generic shell script compiler)

1. Download source shc ( _http://www.datsi.fi.upm.es/~frosal/sources/shc-3.8.7.tgz_ )

SHC * the latest version from that server is shc-3.8.9.tgz *

[root@Redhat6_afgan shc-3.8.7]# pwd
/root/test/shc-3.8.7/shc-3.8.7
[root@Redhat6_afgan shc-3.8.7]#

2. Compile the shc source
[root@Redhat6_afgan shc-3.8.7]# make
cc -Wall -O6  shc.c -o shc
make: cc: Command not found
make: *** [shc] Error 127
[root@Redhat6_afgan shc-3.8.7]#

Check the package gcc already installed or not in system, if there gcc not installed, install that first

[root@Redhat6_afgan shc-3.8.7]#rpm -qa | grep gcc
[root@Redhat6_afgan ~]#  rpm -qa | grep gcc
libgcc-4.4.4-13.el6.x86_64
[root@Redhat6_afgan ~]#

[root@Redhat6_afgan shc-3.8.7]# yum install gcc-c++
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
.... truncated ...
Running Transaction
  Installing     : mpfr-2.4.1-6.el6.x86_64                                                                                        1/10
  Installing     : cpp-4.4.4-13.el6.x86_64                                                                                        2/10
  Installing     : ppl-0.10.2-11.el6.x86_64                                                                                       3/10
  Installing     : cloog-ppl-0.15.7-1.2.el6.x86_64                                                                                4/10
  Installing     : libstdc++-devel-4.4.4-13.el6.x86_64                                                                            5/10
  Installing     : kernel-headers-2.6.32-71.el6.x86_64                                                                            6/10
  Installing     : glibc-headers-2.12-1.7.el6.x86_64                                                                              7/10
  Installing     : glibc-devel-2.12-1.7.el6.x86_64                                                                                8/10
  Installing     : gcc-4.4.4-13.el6.x86_64                                                                                        9/10
  Installing     : gcc-c++-4.4.4-13.el6.x86_64                                                                                   10/10

Installed:
  gcc-c++.x86_64 0:4.4.4-13.el6

Dependency Installed:
  cloog-ppl.x86_64 0:0.15.7-1.2.el6            cpp.x86_64 0:4.4.4-13.el6                  gcc.x86_64 0:4.4.4-13.el6
  glibc-devel.x86_64 0:2.12-1.7.el6            glibc-headers.x86_64 0:2.12-1.7.el6        kernel-headers.x86_64 0:2.6.32-71.el6
  libstdc++-devel.x86_64 0:4.4.4-13.el6        mpfr.x86_64 0:2.4.1-6.el6                  ppl.x86_64 0:0.10.2-11.el6

Complete!
[root@Redhat6_afgan shc-3.8.7]#
[root@Redhat6_afgan ~]#  rpm -qa | grep gcc
gcc-4.4.4-13.el6.x86_64
libgcc-4.4.4-13.el6.x86_64
gcc-c++-4.4.4-13.el6.x86_64
[root@Redhat6_afgan ~]#

After process install gcc was completed,Try again command make the shc

[root@Redhat6_afgan shc-3.8.7]# make
cc -Wall -O6  shc.c -o shc
***     ¿Do you want to probe shc with a test script?
***     Please try...   make test
[root@Redhat6_afgan shc-3.8.7]#
[root@Redhat6_afgan shc-3.8.7]# ls -ltr
total 160
-rw-r--r--. 1 root root 17982 May  9  1996 Copying
-rw-r--r--. 1 root root   336 Feb 22  2003 match
-rw-r--r--. 1 root root  1544 Jun 19  2003 shc.README
-rw-r--r--. 1 root root   155 Jun 19  2003 pru.sh
-rw-r--r--. 1 root root    52 Jun 19  2003 test.csh
-rw-r--r--. 1 root root  3136 Jul  8  2004 shc.1
-rw-r--r--. 1 root root  4558 Jul  8  2004 shc.html
-rw-r--r--. 1 root root   138 Nov 13  2004 test.bash
-rw-r--r--. 1 root root   142 Jan 18  2008 test.ksh
-rw-r--r--. 1 root root 24962 Feb 11  2010 shc.c
-rw-r--r--. 1 root root 24962 Feb 11  2010 shc-3.8.7.c
-rw-r--r--. 1 root root  1940 Feb 11  2010 Makefile
-rw-r--r--. 1 root root  3637 Feb 11  2010 CHANGES
-rwxr-xr-x. 1 root root 37173 Jan 19 15:18 shc
[root@Redhat6_afgan shc-3.8.7]# 

[root@Redhat6_afgan shc-3.8.7]# make install
***     Installing shc and shc.1 on /usr/local
***     ¿Do you want to continue? y
install -c -s shc /usr/local/bin/
install -c -m 644 shc.1 /usr/local/man/man1/
install: target `/usr/local/man/man1/' is not a directory: No such file or directory
make: *** [install] Error 1
[root@Redhat6_afgan shc-3.8.7]#

please ignore the error above, the shc already linked to /usr/local/bin

3.Create shell script file to do test
[root@Redhat6_afgan shc-3.8.7] # vi afgan.sh
#!/bin/bash
echo "please Call Me AFGAN !!!"
:wq!
[root@Redhat6_afgan shc-3.8.7]#
[root@Redhat6_afgan shc-3.8.7]# chmod +x afgan.sh
[root@Redhat6_afgan shc-3.8.7] # ls -ltr afgan.sh
-rwxr-xr-x. 1 root root   45 Jan 19 17:05 afgan.sh
[root@Redhat6_afgan shc-3.8.7]#


4.Try complie the script using shc
[root@Redhat6_afgan shc-3.8.7]# /usr/local/bin/shc  -v -r -T -f afgan.sh
shc shll=bash
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: cc  afgan.sh.x.c -o afgan.sh.x
shc: strip afgan.sh.x
shc: chmod go-r afgan.sh.x
[root@Redhat6_afgan shc-3.8.7]#
[root@Redhat6_afgan shc-3.8.7]# ls -ltr afgan*
-rw-r--r--. 1 root root   45 Jan 19 17:05 afgan.sh
-rw-r--r--. 1 root root 9450 Jan 19 17:08 afgan.sh.x.c
-rwx--x--x. 1 root root 9240 Jan 19 17:08 afgan.sh.x
[root@Redhat6_afgan shc-3.8.7]#

After compile shell script file, shc will create 2 files : afgan.sh.x and afgan.sh.x.c 

[root@Redhat6_afgan shc-3.8.7]# file afgan.sh
afgan.sh: Bourne-Again shell script text executable
[root@Redhat6_afgan shc-3.8.7]# file afgan.sh.x.c
afgan.sh.x.c: ASCII C program text
[root@Redhat6_afgan shc-3.8.7]# file afgan.sh.x
afgan.sh.x: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[root@Redhat6_afgan shc-3.8.7]#

5. Test running the ooutput file from shc
[root@Redhat6_afgan shc-3.8.7]# pwd
/root/test/shc-3.8.7/shc-3.8.7
[root@Redhat6_afgan shc-3.8.7]# ls -ltr afgan*
-rwxr-xr-x. 1 root root   45 Jan 19 17:05 afgan.sh
-rw-r--r--. 1 root root 9450 Jan 19 17:08 afgan.sh.x.c
-rwx--x--x. 1 root root 9240 Jan 19 17:08 afgan.sh.x
[root@Redhat6_afgan shc-3.8.7]# ./afgan.sh.x
please Call Me AFGAN !!!
[root@Redhat6_afgan shc-3.8.7]#

6. Rename file afgan.sh.x with whatever your needed
[root@Redhat6_afgan shc-3.8.7]# mv afgan.sh.x kicep
[root@Redhat6_afgan shc-3.8.7]# ./kicep
please Call Me AFGAN !!!
[root@Redhat6_afgan shc-3.8.7]#

0 komentar:

Post a Comment

 
footer