Open suntong opened 10 years ago
Check out my new version 3.9.0 at https://github.com/neurobin/shc I have added [-o filename] option to output to a specific file, and the install have proper man page now.
Jahidul,
Thanks
It runs good in my case:
shc -f match
echo ./match.x bash > /tmp/test.sh
sudo sh -x /tmp/test.sh
Output:
+ ./match.x bash
/usr/bin/bashbug
/usr/bin/checkbashisms
/usr/bin/dh_bash-completion
/bin/bash
/bin/rbash
[3399] PAUSED... Hit return!
"Now put that into shell scripts"...
script new:
#!/bin/sh
shc -f match
echo ./match.x bash > /tmp/test.sh
sudo sh -x /tmp/test.sh
running ./new gives the same output as before
Removing that sudo
when invoking /tmp/test.sh
? -- Running under sudo
is different from running from with shell scripts.
You will need to make the executable like this at first for that:
shc -rT -f match
Any way, I have altered the -T option so that it will be traceable by default. It's now -U which means Untraceable. If not specified it will take traceable=true, and create a binary which can be executed by users other than root.
N.B: -r option is for a release version which will work on other systems as well
Currently that's a problem I am facing. Even C or C++ code compiled with gcc isn't giving me the required permission to run it with normal user.
Look in the closed issue in this project for the (systematic) solution, that doesn't need you to alter the make method.
That systematic solution, basically changes #if !TRACEABE to #if !defined(TRACEABLE). But a common practice of initializing variables could effectively protect it from misbehaving, and basically that's what I have done. And thus #if !TRACEABLE works fine as it should be. There was no need to use #if !defined for me. And along the way, I altered the logic, so that -T option becomes a default. And if anyone doesn't want it, they can put -U option instead. In that case it will no longer be executed without root.
And I have released it in launchpad. You can install it by:
sudo add-apt-repository -y ppa:neurobin/ppa
sudo apt-get update
sudo apt-get install shc
All the best...
And I have released it in launchpad.
Can It be used in shell scripts?
Can It be used in shell script?
This seems kinda ambiguous to me, if you could give me an example, I could help you better. Anyway, if you mean using shc in script, then of course, you can.
Here's an script named test:
#!/bin/bash
shc -f match
./match.x
match is another script in the same folder as test. it will compile match and run it.
N.B: As shc is installed, it is global command, you can access it from anywhere. It resides in /usr/bin
Thanks, Please post your output of "sh -x /tmp/test.sh
" running as a normal user, after having done
echo ./match.x bash > /tmp/test.sh
Thanks again.
It shows error:
+ ./match.x bash
/bin/sh: 0: Can't open bash
If you run without the sh command (simply /tmp/test.sh), it runs as expected. It seems it is having a hard time interpreting the paths.
If you run without the sh command (simply /tmp/test.sh), it runs as expected.
Oh, good to know. Thanks!!!
bash /tmp/test.sh works too...
Yep, noticed that as well. Seems that shc-3.8.9 is hard wired against bash. Updating my OP...
/usr/bin/sh is actually a link to /usr/bin/bash, so practically sh invokes bash by default...
To duplicate, compile match.x first:
Verify it works:
Now put that into shell scripts:
Ref: http://sfxpt.wordpress.com/2014/02/23/shc-3-8-9-is-not-usable/
[Update]:
Seems that shc-3.8.9 is hard wired to
bash
-- everythingbash
works whereas everything Bourne shell (sh) won't work:I.e., scripts with Bourne shell (sh) Shebang will hung until break.
However, everything
bash
works. I.e. bothbash -x /tmp/test.sh
and the following script work:Thanks to Jahidul Hamid (neurobin) finding that out.