管道或回显密码到RAR命令?

时间:2014-12-14 21:36:43

标签: macos bash shell rar

我试图在密码保护的存档上使用命令行中的RAR:

$ rar t spe_05_1.part13.rar

RAR 5.11   Copyright (c) 1993-2014 Alexander Roshal   27 Aug 2014
Trial version             Type RAR -? for help

Enter password (will not be echoed) for spe_05_1.part13.rar: 

RAR似乎没有密码开关。它提供了一种在存档上设置密码的方法,但我找不到将密码传递给命令以进行测试(t命令)或提取(x命令)的方法:

$ rar | grep -i password
  hp[password]  Encrypt both file data and headers
  p[password]   Set password
  p-            Do not query password

我需要自动输入密码(我必须尝试多个密码),因此我尝试使用echopipe

$ echo diespe120 | rar t spe_05_1.part13.rar

RAR 5.11   Copyright (c) 1993-2014 Alexander Roshal   27 Aug 2014
Trial version             Type RAR -? for help

Enter password (will not be echoed) for spe_05_1.part13.rar: 

不幸的是,这促使了我。

如何在脚本中自动输入RAR密码?


PASSWORDS=
for i in {100..150}
do
    pw=$(printf "diespe%03d" $i)
    PASSWORDS+="$pw " 
done

for PASSWORD in $PASSWORDS
do
    echo $PASSWORD | rar t spe_05_1.part13.rar
    if [ $? -eq 0 ]; then
        echo "Password is " $PASSWORD
        break
    fi
done

1 个答案:

答案 0 :(得分:3)

  

如何在脚本中自动输入RAR密码?

要自动化,请勿使用管道。请改用shell变量。尝试:

for PASSWORD in $PASSWORDS
do
    rar t -p"$PASSWORD" spe_05_1.part13.rar
    if [ $? -eq 0 ]; then
        echo "Password is '$PASSWORD'"
        break
    fi
done