gpg+expect自动解密脚本

来源:互联网 发布:sql查询分析器使用 编辑:程序博客网 时间:2024/06/01 17:18

第一次写linux的这种脚本,坑点在于每次使用加密都需要输入私钥,为了让程序顺利运行,使用expect来编写运行脚本.

另一个坑点就是必须要先安好tcl,然后安装expect,然后才能运行.

脚本内容就是循环执行解密密令.

#!/usr/local/bin/expect -f  //注意将路径替换成expect路径,可用"which expect"命令查询while 1 {spawn  gpg --output demo.de.txt --decrypt demo.en.txtexpect    -exact    "请输入密码:"send "1\r"expect -exact "文件‘demo.de.txt’已存在。 是否覆盖?(y/N)"send "y\r"interact}

spawn后加要执行的命令

expect -exact加需要输入的一行中电脑输出的内容

send加你需要自动输入的内容,如密码等

interact 结束

linux下运行命令为:

expect auto.sh //auto.sh为脚本文件名

总的来说这种东西写出来了,临时用用还行,但是具体的linux脚本编写还差得远,之前查到expect大都是编写vpn时候用到在断网时自动链接vpn时自动输入密码.以后有时间再试试吧.

0 0
原创粉丝点击