This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Exec issue...

Help for those learning Tcl or writing their own scripts.
Post Reply
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Exec issue...

Post by BeBoo »

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: Select all

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: Select all

putserv "PRIVMSG $chan :\002\00305\[\003 \00312EXECUTOR\003 \00305\]\002\003 [exec [lindex $args 0]]"
Thanks for any help anyone can offer!
Online
User avatar
CrazyCat
Revered One
Posts: 1334
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

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.
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

Without what quotes? I typed: !exec ps -u (with no quotes)

I get the following with the .tcl command in PL:

Code: Select all

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"
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

proc docommand {cmdline} {
 set _t [split $cmdline " "]
 return [exec -- [lindex $_t 0] [join [lrange $_t 1 end] " "]]
}
NML_375
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

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!!!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

Just one binding: !exec

I will post my script so it can be critiqued when I'm done cleaning it up.

heh
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Then, pardon me for asking, what use would you have of using "args"?
NML_375
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

Because I call the commands I want to be exec'd... for instance:

!exec ps -u
or
!exec uptime
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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
B
BeBoo
Halfop
Posts: 42
Joined: Wed Sep 26, 2007 1:44 am

Post by BeBoo »

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!
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Try something like this then:

Code: Select all

if {[catch {exec who} status]} {
#error condition, error-message stored in $status
} {
#Successful, any output stored in $status
}
NML_375
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Scripts that run exec, especially with unchecked input, are dangerous. Something to keep in mind when writing this script.
Script security
Post Reply