是否可以在 irc 中 运行 一个 bash 命令?
Is it possible to run a bash command in irc?
在 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 正在发送带引号的字符串但不确定如何解决该问题
问题是您将 $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"
}
}
在 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 正在发送带引号的字符串但不确定如何解决该问题
问题是您将 $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"
}
}