Bash 脚本跳过密码保护档案的提取 [英] Bash script to skip extraction of password protected archives
问题描述
我有一个脚本,它使用以下命令对某些文件夹中的特定 zip 和\或 tar.gz 档案进行批量提取:
I have a script, which performs mass extraction of specific zip and\or tar.gz archives in some folders using command:
unzip -o "$zip_path" -d "$destination_folder"
不幸的是,当存档受密码保护时,脚本会停止并等待密码输入.
Unfortunately, when archive is password-protected, script stops and waiting for password input.
有什么办法可以省略密码进入阶段,不中断脚本运行?
Is there any way to omit password entering stage to not interrupt script running?
附言无需提取受密码保护的文件.仅省略此存档.类似的东西:
P.S. There is no need to extract password-protected files. Only omit this archives. Something like:
if "$zip_path" [ determine that archive is password-protected ]; then
echo "Password-protected"
elif "continue script execution"
fi
推荐答案
对于 zip 文件,您可以使用 -P
标志指定虚拟(错误)密码.对于未加密的文件,它将被忽略,对于加密文件,您将收到警告并且该文件将被跳过.例如:
For zip files, you can specify a dummy (wrong) password with the -P
flag.
For non-encrypted files it will be ignored,
for encrypted files you will get a warning and the file will be skipped. For example:
unzip -P x -o "$zip_path" -d "$destination_folder"
对于 tar 文件,加密不是标准功能,所以我不确定您的意思.您可以尝试将 stdin 从 /dev/null
重定向到脚本,使其无法读取并跳到下一个文件:
For tar files, encryption is not a standard feature, so I'm not sure you what you mean. You could try to redirect stdin to the script from /dev/null
to make it fail to read and skip over to the next file:
tar -xvzf "$tgz_path" --directory "$destination_folder" < /dev/null
如果这不起作用,那么您可以尝试expect
.
If this doesn't work, then you can try expect
.
这篇关于Bash 脚本跳过密码保护档案的提取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!