Bash 为每个结果创建单独的文件
我有一个bash脚本,如下所示:Bash 为每个结果创建单独的文件,bash,shell,for-loop,Bash,Shell,For Loop,我有一个bash脚本,如下所示: SITE_LIST=/home/wps/sites.txt for file in `cat $SITE_LIST` do /usr/bin/wpscan --update --no-color --url $file --disable-tls-checks --follow-redirection --enumerate utp > "$file".txt done 运行此脚本时,我得到以下输出: ./wpscan
SITE_LIST=/home/wps/sites.txt
for file in `cat $SITE_LIST`
do
/usr/bin/wpscan --update --no-color --url $file --disable-tls-checks --follow-redirection --enumerate utp > "$file".txt
done
运行此脚本时,我得到以下输出:
./wpscan_script_2: line 15: www.need_help.com: No such file or directory
./wpscan_script_2: line 15: www.need_help.com: No such file or directory
./wpscan_script_2: line 15: www.need_help.com: No such file or directory
./wpscan_script_2: line 15: www.need_help.com: No such file or directory
./wpscan_script_2: line 15: www.need_help.com: No such file or directory
./wpscan_script_2: line 15: www.need_help.com: No such file or directory
注意我用网站www.need\u help for security替换了实际的网站。这不是实际站点的名称
我试图做的是将每个结果导入到自己的文件中。我目前在这方面没有成功。我从错误中发现,您的文件包含以下行:
www.need\u help.com/xyz
(与xyz
任何内容无关)
这意味着,“$file.txt
最终会扩展到www.need\u help.com/xyz.txt
因此,您的脚本尝试将输出写入文件夹www.need_help.com
中的文件xyz.txt
,但由于该文件夹不存在而失败
错误消息令人困惑但准确:www.need_help.com:没有此类文件或目录
您可能希望将所有不需要的字符替换为其他字符,例如仅保留字母、数字和点
for url in `cat "$SITE_LIST"`
do
file="$(printf '%s' "$url" | sed 's/[^A-Za-z0-9\.]/_/g')"
/usr/bin/wpscan --update --no-color --url "$url" --disable-tls-checks --follow-redirection --enumerate utp > "$file".txt
done
如果有很多适合您口味的替代品,您可以修改sed正则表达式。但它至少应该将所有/
替换为例如:sed's#/#-#g'
编辑:没有注意到您也使用$file作为urlwpscan\u script\u 2第15行的内容是什么?@user000001/usr/bin/wpscan--update--no color--url$file--disable tls check--follow redirection--enumerate utp>“$file”.txt我有一些回音语句被删除了。很抱歉,您应该总是双引号外壳变量
--url“$file”
不要使用for
循环对文件进行迭代;请参见.shellcheck.net将为循环标记未引用的参数和。