bash - 是否可以在 irc 中运行 bash 命令?
问题描述
在 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 Artist - Album
所以我需要 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"
}
}
推荐阅读
- function - 有没有像 sqlite3“函数”这样的东西?
- r - 计算 R 中每一列的出现次数
- airflow - 如何解码气流表 dag_run 列 conf 值
- python - 如何更改python模块中的函数?
- c - 为什么我的线性代数 C 程序会因非方阵而失败?
- json - 如何检索本地 json 数据以将其显示在谷歌地图上?
- azure - 来自联合 Azure 租户的用户可以使用相同的电子邮件向我的 Azure 租户注册吗?
- azure-functions - Azure 函数消耗计划超时
- .net - 在 .net 中使用 SAML 断言准备 Soap 服务
- python - 将数据框中的特定单元格拆分为值列表