LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-16-2010, 02:06 PM   #1
rivacom
LQ Newbie
 
Registered: Jul 2010
Posts: 19

Rep: Reputation: 0
Expect command with PGP.


So I'm trying to make a simple enough script that does pgp decrypting for us and exports it for use.

Problem being, I run into the issue where the secret key needs to be entered when I run the gpg command. So I am trying to get the expect command to output the secret key. So below is my code, maybe someone can help figure it out. It basically doesn't do anything and it waits for someone to enter the key manually.

Code:
#! /bin/bash
#PGP Decryption Bash Script
clear
d=`date +%Y%m%d`
expect "*?passphrase:*"
send -- "password\r"
gpg -d file.txt.pgp > file_$d.txt
echo "file extracted"
exit
 
Old 08-16-2010, 02:48 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by rivacom View Post
So I'm trying to make a simple enough script that does pgp decrypting for us and exports it for use.

Problem being, I run into the issue where the secret key needs to be entered when I run the gpg command. So I am trying to get the expect command to output the secret key. So below is my code, maybe someone can help figure it out. It basically doesn't do anything and it waits for someone to enter the key manually.

Code:
#! /bin/bash
#PGP Decryption Bash Script
clear
d=`date +%Y%m%d`
expect "*?passphrase:*"
send -- "password\r"
gpg -d file.txt.pgp > file_$d.txt
echo "file extracted"
exit
Right...because the thing that generates the expect conditon (the gpg command), is BELOW the expect. Move it above.
 
Old 08-16-2010, 08:45 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
I might be wrong, but this is using the expect command and send command in a bash script.

AFAIK expect is a TCL extension so you'd have to write your expect script in Expect, not in bash.

http://www.tcl.tk/man/expect5.31/index.html

jlinkels
 
Old 08-17-2010, 08:18 AM   #4
rivacom
LQ Newbie
 
Registered: Jul 2010
Posts: 19

Original Poster
Rep: Reputation: 0
I've tried putting expect above and below with no luck. Jlinkels, is there a easier way to do it? Be nice to keep everything in bash without learning and putting in another set of programs.
 
Old 08-17-2010, 09:50 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Maybe you are trying to do something the hard way which is really easy.

You see, expect is used when you start another program (like telnet), and you expect something from that external program like username:. The instead of you as human user enter this information, you let expect send the information from your script to the external program (like telnet).

If I understand right, what you want to do is to prompt the user for a passphrase, read that passphrase from the user and run pgp with that information?

That would be something like this:
Code:
#!/bin/sh
echo -n "enter passphrase"
read pf
gpg --passphrase $pf -d file.txt.pgp > file_$d.txt
Please also refer to the Advanced Bash Scripting Guide, the link is in my signature.

Now take into account that I don't know exactly how to use gpg. If you want to start the gpg program from within your script, have gpg ask for a passphrase and let your scrip supply it, that is exactly how I described that in the second paragraph. You'd have to use expect.

jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
chroot: expect: command not found dbbolton Linux From Scratch 11 12-06-2009 07:33 PM
[SOLVED] Execute a command using expect visu_kvg Linux - Newbie 4 08-05-2009 10:08 AM
How to use expect command? jprathap Linux - Newbie 1 11-21-2008 10:30 PM
Command Prompt PGP for Email mchirico LinuxQuestions.org Member Success Stories 0 07-23-2004 10:22 PM
using Expect command to automate prgms mehargags Linux - General 9 06-15-2003 07:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration