Operating System - HP-UX
1827474 Members
1968 Online
109965 Solutions
New Discussion

Re: How to make a bourne shell script executable?

 
SOLVED
Go to solution
Chua Wen Ching
Regular Advisor

How to make a bourne shell script executable?

I had write some bourne shell scripts but i do not want to reveal the source code. Can i make the script executable? Can chmod do that? Thank you.
wenching
25 REPLIES 25
Pete Randall
Outstanding Contributor
Solution

Re: How to make a bourne shell script executable?

chmod a+x

Pete

Pete
Bill Hassell
Honored Contributor

Re: How to make a bourne shell script executable?

Not possible. Setting the execute bit allows the program to be started as a potential process but in order for the shell to see that the file type is a shell script, it must be read. And of course, the shell script is an interpreted language so each line must be read by the shell. You can try: chmod 711 your-file which makes it executable only, but the shell cannot open the file.

IMPORTANT: if you make a file unreadable for yourself (ie, chmod 111 your-file) then you can no longer read or edit the file. The root user will have to restore read privileges for you.


Bill Hassell, sysadmin
Jerome Baron
Respected Contributor

Re: How to make a bourne shell script executable?

Hi,

For me a script must been have read right. I think that you can't make script executable and not readable.
A chmod 111 give this error :
sh: ./script: Cannot find or open the file.

Regards,
Jerome
Pete Randall
Outstanding Contributor

Re: How to make a bourne shell script executable?

Makes sense it would have to be readable - learned something new already today!

Pete

Pete
Chua Wen Ching
Regular Advisor

Re: How to make a bourne shell script executable?

Hmm...so it is impossible to make bourne shell script executable? Is there any third party utility to convert? Anyway thanks a lot.
wenching
H.Merijn Brand (procura
Honored Contributor

Re: How to make a bourne shell script executable?

As long as you have write access to the containing folder, you can chmod +r the 111 file yourself IMHO. Don't need no root for that.

$ id
uid=9999(guest) gid=999(common) groups=200(softwr),700(dba),703(oinstall)
$ which chmod
/usr/bin/chmod
$ ls -ld .
drwxrwxrwx 21 root root 11264 Oct 14 13:42 .
$ echo id >id.sh
$ ./id.sh
sh: ./id.sh: Execute permission denied.
$ chmod 555 id.sh
$ ./id.sh
uid=9999(guest) gid=999(common) groups=200(softwr),700(dba),703(oinstall)
$ chmod 111 id.sh
$ ./id.sh
sh: ./id.sh: Cannot find or open the file.
$ chmod 555 id.sh
$ ./id.sh
uid=9999(guest) gid=999(common) groups=200(softwr),700(dba),703(oinstall)
$
Enjoy, Have FUN! H.Merijn
harry d brown jr
Honored Contributor

Re: How to make a bourne shell script executable?


Chua Wen,

That's why it's time to learn perl. You can convert perl to c, compile it and have an executable. Once you have a newer version of perl installed, check out perlcc.

live free or die
harry
Live Free or Die
Chua Wen Ching
Regular Advisor

Re: How to make a bourne shell script executable?

Dear procura, i saw you reply on chmod 555 id.sh and chmod 111 id.sh. I will learn perl slowly but it takes some time. All i want is that:
when i convert abc.sh to executable, i can run it as usual by typing abc.sh.
But when i vi abc.sh, it will not display any codes but executable. Example if i vi a directory, it will tell me the file is a directory right. Thank you.
wenching
H.Merijn Brand (procura
Honored Contributor

Re: How to make a bourne shell script executable?

WHY do you want to make it compilable? Even perlcc will not help you, because there are perfectly working de-parsers (of course available in perl modules :)

If you /need/ to hide the source code (for whatever valid reason), you're bound to compiling languages like C, Pascal, Ada, or Fortran.

Perl has the huge advantage, that it's scripts run almost anywhere (given that the perl installed on the target system is new enough to support the features used in the script). Most - if not all - perl4 scripts will still run under perl-5.8.0 as well on HP-UX 09.00 as on M$Win32 (as long as you're not depending on fork's alarms and other timer/signal stuff) and MacOS-X. The fact that the source is `readable', does not mean that you loose copyright. It's *your* source. Make it stand out in the headers, and make good contracts that verify the use of your scripts.
Enjoy, Have FUN! H.Merijn
Chua Wen Ching
Regular Advisor

Re: How to make a bourne shell script executable?

It sounds complicated here. Any solutions using bourne shell other than perl? Thank you. :D
wenching
Yogeeraj_1
Honored Contributor

Re: How to make a bourne shell script executable?

hi,

please have a look at http://www.cactus.com/products/cactus/shell-lock.html

Quote:
==============================
SHELL-LOCK(tm) is a shell script compiler which actually turns your shell scripts into binary executable files so that they can not be modified or tampered with by your customer or competitor. In addition, we offer special Code Shells which allow you to compile your shell scripts for platforms other than the one you write scripts on.
==============================

Hope this is what you are looking for. There are a few other products like this...

Regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Chua Wen Ching
Regular Advisor

Re: How to make a bourne shell script executable?

I will try the third party software. Is it possible to write a bourne shell script which act to convert the source code to executable? :D
wenching
Gerard Leclercq
Trusted Contributor

Re: How to make a bourne shell script executable?

Just an idea ...

Why not write a simple c program :

Put your script as text in a pointer,
Copy your pointer in a temporary file,
Execute system(temporary file),
Delete temporary file.

You could slice your script in several pointers, if the
execution time is long enough to allow somebody
find your temporary file.

Gerard
Chua Wen Ching
Regular Advisor

Re: How to make a bourne shell script executable?

I am not that good in c programming. Is there any sample c program which can do that? I hope bourne shell script also can do that. Thank you.
wenching
Yogeeraj_1
Honored Contributor

Re: How to make a bourne shell script executable?

hi,
The first C program, you would write:
=============================
SLX1:tmp>vi first.c
#include
void main(void)
{
printf("\nhello world \n");
}
~
"first.c" 5 lines, 67 characters
SLX1:tmp>cc first.c -o first
SLX1:tmp>./first

hello world
SLX1:tmp>
==============================

for more complex programs, you should start opening C books ;)

regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
harry d brown jr
Honored Contributor

Re: How to make a bourne shell script executable?

Chua Wen,

TO make a perl program executable you do this:

(1) Write the perl program
(2) test it to make sure it works
(3) perlcc -o perlprogramname executablename
(4) test "executablename"

Now, that's easy!

live free or die
harry
Live Free or Die
Gerard Leclercq
Trusted Contributor

Re: How to make a bourne shell script executable?

I am not a good c programmer, please professionals of c programming, do not read what follows ...

Dear Chua Wen Ching,

Please try this :

#include
#include
#include

main(argc, argv)
int argc;
char *argv[];
{
FILE *fildes;

fildes = fopen(".fich_tmp", "wt");

fprintf(fildes, "echo compiled script test\n");
fprintf(fildes, "ll\n");

fclose(fildes);

system("sh .fich_tmp;rm .fich_tmp");

}

The dot before fich_tmp makes it harder (just a little bit) for somebody else to see the file.

Gerard


Rory R Hammond
Trusted Contributor

Re: How to make a bourne shell script executable?




http://hpux.cs.utah.edu/
has source code and hpux binaries for "shc" a shell compiler that is free. The last time I used it it worked fine.

There are a 100 ways to do things and 97 of them are right
H.Merijn Brand (procura
Honored Contributor

Re: How to make a bourne shell script executable?

Simple C-solutions like posted above won't help you obfuscating your source from peering eyes of people with experience.

# strings blah

(given that blah is the executable) will probably show you the complete script in the correct order.

So *if* you go for a solution like this, insert fake statements in the C program:


printf ("real statement\n");
if (0) printf ("rm -rf /\n");
printf ("another real statement\n");
strcpy (a, "exit 1\nyet another real statement\n");
printf ("%s", a + 7);
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor

Re: How to make a bourne shell script executable?

Ehhh, and don't use fixed file names for temporary files, there is a great function for that: mktemp ()

# man 3 mktemp
Enjoy, Have FUN! H.Merijn
Juan Manuel López
Valued Contributor

Re: How to make a bourne shell script executable?

Hi all.
You have to give execute permision to your script file:
chmod 700 < file >

I hope this help you.


Juanma.
I would like to be lie on a beautiful beach spending my life doing nothing, so someboby has to make this job.
Chua Wen Ching
Regular Advisor

Re: How to make a bourne shell script executable?

Sorry for not replying as i was very busy these few days.

Dear Rory R Hammond
--------------------
I had download the file shc-2.4a-sd-10.20.depot. I am able to unzip it but how am i suppose to install/run the shc? If i am not a unix root/administrator and just a normal user, can i still install it into my account. Thank you.

Dear Juan Manuel Lo
--------------------
When i chmod 700 < test.sh > there is an error:
sh: Syntax Error: `newline or ;' is not expected. I not sure whether HP-UX 10.20 can do that.

Dear Gerard Leclercq
---------------------
Thanks for your C code. But when i want to make test.sh (a sample script) executable, anything to do with temporary files? Is it you want me to name test.sh to .test? Anyway can you explain more details about your code. Maybe comments. I am not that good in C. :D

Dear procura
------------
I had read through the man 3 mktemp but it does not teach me how to use it. Is it implemented in C rather than bourne shell script? Any sample implmentation on bourne/Posix script.

Dear Yogeeraj
-------------
Cool...i just know how to make a c program executable rather than keep using the old way (a.out). Thanks a lot. But i want to make a bourne shell script executable rather than C or perl.

Anyway thanks for your replies. It really help me learn more about UNIX. Thank you.

wenching
Rory R Hammond
Trusted Contributor

Re: How to make a bourne shell script executable?

If you want, I will send the source code and you can then install it in you bin directory
There are a 100 ways to do things and 97 of them are right
Rodney Hills
Honored Contributor

Re: How to make a bourne shell script executable?

If the source is ultra sensitive then I have 2 recommendations.

1)
You can use "sudo" to run it.

sudo abc.sh

The downside is the shell script will run as "root". But then no one can look at the source.

--- or ---

2) You can use group permissions on a wrapper script. Not entirely recommended, but can be made secure.

script1.sh has group ownership of "secret" and the set gid bit is set (chmod 2755 script1).
abc.sh has group ownership of "secret" and the group permissions are read (chmod 755 abc.sh).

abc.sh is visible only to people who are members of the "secret" group. script1.sh is visible to everyone. When script1.sh is ran, the script will have access to run abc.sh.

my 2 cents
-- Rod Hills

There be dragons...