在ssh中,我可以使用以下命令执行bash脚本
./myscript.sh -g House -y 2019 -u https://someurl.com Artist - Album
脚本从一个目录读取,该目录包含各个艺术家的子文件夹,但是当我从IRC执行触发器时,它告诉我文件夹名称无效
irc触发器是!myscript -g House -y 2019 -u https://someurl.com Artist - Album
。
就目前而言,我使用此代码来触发IRC命令
proc dupe:myscript {nick host hand chan arg} {
set _bin "/home/eggdrop/logfw/myscript.sh"
if {[catch {exec $_bin "$arg" &} error]} {
putnow "PRIVMSG $chan :Error.. $error"
} else {
putnow "PRIVMSG $chan :Running.. $arg"
}
}
我遇到的错误是找不到文件夹名称,因为它报告为-g House -y 2019 -u https://someurl.com艺术家-专辑
所以我需要irc或bash删除optarg部分,以便仅在irc中显示文件夹名称。
我认为出现错误是因为tcl正在发送带引号的字符串,但不确定如何解决该问题
答案 0 :(得分:0)
问题是您将$arg
作为一个字符串而不是多个参数发送。解决方法可能是:
if {[catch {exec $_bin {*}$arg &} error]} {
(其余代码将相同。)
您可能需要采取一些额外的措施来防止混蛋进行重定向和其他恶作剧。这很容易:
proc dupe:myscript {nick host hand chan arg} {
set _bin "/home/eggdrop/logfw/myscript.sh"
# You might need this too; it ensures that we have a proper Tcl list going forward:
set arglist [split $arg]
# Check (aggressively!) for anything that might make exec do something weird
if {[lsearch -glob $arglist {*[<|>]*}] >= 0} {
# Found a potential naughty character! Tell the user to get lost…
putnow "PRIVMSG $chan :Error.. bad character in '$arg'"
return
}
if {[catch {exec $_bin {*}$arglist &} error]} {
putnow "PRIVMSG $chan :Error.. $error"
} else {
putnow "PRIVMSG $chan :Running.. $arg"
}
}