Bash 跳过密码保护档案提取的脚本
Bash script to skip extraction of password protected archives
我有一个脚本,它使用以下命令对某些文件夹中的特定 zip and\or tar.gz 存档执行批量提取:
unzip -o "$zip_path" -d "$destination_folder"
不幸的是,当存档受密码保护时,脚本停止并等待密码输入。
有什么方法可以省略密码进入阶段而不中断脚本 运行?
P.S。无需提取受密码保护的文件。仅省略此档案。
类似于:
if "$zip_path" [ determine that archive is password-protected ]; then
echo "Password-protected"
elif "continue script execution"
fi
对于 zip 文件,您可以使用 -P
标志指定虚拟(错误)密码。
对于未加密的文件,它将被忽略,
对于加密文件,您将收到警告并且文件将被跳过。例如:
unzip -P x -o "$zip_path" -d "$destination_folder"
对于 tar 个文件,加密不是标准功能,所以我不确定您的意思。您可以尝试将标准输入从 /dev/null
重定向到脚本,使其无法读取并跳到下一个文件:
tar -xvzf "$tgz_path" --directory "$destination_folder" < /dev/null
如果这不起作用,那么您可以尝试 expect
。
我有一个脚本,它使用以下命令对某些文件夹中的特定 zip and\or tar.gz 存档执行批量提取:
unzip -o "$zip_path" -d "$destination_folder"
不幸的是,当存档受密码保护时,脚本停止并等待密码输入。
有什么方法可以省略密码进入阶段而不中断脚本 运行?
P.S。无需提取受密码保护的文件。仅省略此档案。 类似于:
if "$zip_path" [ determine that archive is password-protected ]; then
echo "Password-protected"
elif "continue script execution"
fi
对于 zip 文件,您可以使用 -P
标志指定虚拟(错误)密码。
对于未加密的文件,它将被忽略,
对于加密文件,您将收到警告并且文件将被跳过。例如:
unzip -P x -o "$zip_path" -d "$destination_folder"
对于 tar 个文件,加密不是标准功能,所以我不确定您的意思。您可以尝试将标准输入从 /dev/null
重定向到脚本,使其无法读取并跳到下一个文件:
tar -xvzf "$tgz_path" --directory "$destination_folder" < /dev/null
如果这不起作用,那么您可以尝试 expect
。