| View previous topic :: View next topic |
| Author |
Message |
BeBoo Halfop
Joined: 26 Sep 2007 Posts: 42
|
Posted: Fri Oct 26, 2007 1:40 pm Post subject: Exec issue... |
|
|
Hey everyone. I am making a simple exec tcl script that only I can run with my eggie that will do little commands on my shell for me instead of logging into it to do a simple task. Anyway, my problem is, I can get it to run single word commands such as "uptime" and "pwd" but i can't get it to do anything that has a switch needed such as "ps -x". I get the following error:
| Code: | | Tcl error [techjoose::runit]: couldn't execute "ps -x": no such file or directory |
Any ideas on how this could work? My script is quite simple and basic:
| Code: | | putserv "PRIVMSG $chan :\002\00305\[\003 \00312EXECUTOR\003 \00305\]\002\003 [exec [lindex $args 0]]" |
Thanks for any help anyone can offer! |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
Posted: Fri Oct 26, 2007 1:47 pm Post subject: |
|
|
without the quotes?
I've tried in PL: .tcl exec ps -ux
It works, making a lot off errors because it tries to execute the output. _________________ https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
| Back to top |
|
 |
BeBoo Halfop
Joined: 26 Sep 2007 Posts: 42
|
Posted: Fri Oct 26, 2007 1:51 pm Post subject: |
|
|
Without what quotes? I typed: !exec ps -u (with no quotes)
I get the following with the .tcl command in PL:
| Code: | 1:48pm (BeBoo) .tcl exec ps -ux
1:48pm (optix) What? You need '.help' |
The thing is, I'd like the output to go to the chan... Logging into my eggie just to run a command is just as bad as logging into the shell... I'd rather just be able to type "!exec ps -ux" |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Oct 26, 2007 2:05 pm Post subject: |
|
|
First off, try to avoid using the name "args" for any variable, unless explicitly intended to use it's special feature.
Secondly, you'll have to separate the arguments from the command in the cmd-line string, and pass them as a separate argument to exec.
A simple example:
| Code: | proc docommand {cmdline} {
set _t [split $cmdline " "]
return [exec -- [lindex $_t 0] [join [lrange $_t 1 end] " "]]
}
|
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
BeBoo Halfop
Joined: 26 Sep 2007 Posts: 42
|
Posted: Fri Oct 26, 2007 2:16 pm Post subject: |
|
|
I am using it's feature... It's in my proc... proc runit {nick uhost handle chan args} {
That works great! Now, because the commands that I will run, most of them are multi-lined and would like all the lines to appear in the output. How would I determine the end of the line? Would it be \n?
Thanks!!! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Oct 26, 2007 2:19 pm Post subject: |
|
|
So you use several different types of bindings to trigger that proc?
Ah well, newlines would generally be \n yes, possibly except on "odd" (windows) platforms... _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
BeBoo Halfop
Joined: 26 Sep 2007 Posts: 42
|
Posted: Fri Oct 26, 2007 2:26 pm Post subject: |
|
|
Just one binding: !exec
I will post my script so it can be critiqued when I'm done cleaning it up.
heh |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Oct 26, 2007 2:27 pm Post subject: |
|
|
Then, pardon me for asking, what use would you have of using "args"? _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
BeBoo Halfop
Joined: 26 Sep 2007 Posts: 42
|
Posted: Fri Oct 26, 2007 2:37 pm Post subject: |
|
|
Because I call the commands I want to be exec'd... for instance:
!exec ps -u
or
!exec uptime |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Oct 26, 2007 2:46 pm Post subject: |
|
|
So?
Still only gets passed to the proc as a single parameter... Hence you get the whole commandline when doing [lindex $args 0].
in fact, you'd get the same result if you'd replace "args" with "text", and "[lindex $args 0]" with "$text" in your script _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
BeBoo Halfop
Joined: 26 Sep 2007 Posts: 42
|
Posted: Fri Oct 26, 2007 3:11 pm Post subject: |
|
|
Thanks. I've made that change.
One other question... If I were to run a command such as 'who' by !exec who (which is not allowed on the shell), it outputs the "Permission denied" as a TCL error in the PL... Is there a way to detect if it's an error of some sort and have it output it to the channel anyway?
Thanks! |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Fri Oct 26, 2007 5:31 pm Post subject: |
|
|
Try something like this then:
| Code: | if {[catch {exec who} status]} {
#error condition, error-message stored in $status
} {
#Successful, any output stored in $status
} |
_________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Fri Oct 26, 2007 7:18 pm Post subject: |
|
|
Scripts that run exec, especially with unchecked input, are dangerous. Something to keep in mind when writing this script.
Script security |
|
| Back to top |
|
 |
|