pass a password to an application


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting pass a password to an application
# 1  
Old 07-18-2009
Bug pass a password to an application

Hi folks

I am new to shellscripting and I try to automate & guify some jobs.
Suppose I have a variable the stores a passwd and an application like "gpg" or "zip" to run from withn the script.

how do I pass that passwd (the content of the variable) to the application being called?

eg.

#/bin/bash
passwd=$1
gpg -d ~/thegpgfile.gpg


running this my terminal sits there waiting for me to enter a passwd. How do I automaticaly use the $passwd so the script continues execution without me interacting?

thank you in advance

p.s. excuse the english. its not me native language
# 2  
Old 07-18-2009
Quote:
Originally Posted by latenite
...
how do I pass that passwd (the content of the variable) to the application being called?
...
For better control, you may want to try out "Expect" scripting - Expect - Expect - Home Page

Whereas a kludge using just shell scripts is as follows:

Code:
$ 
$ file testfile.*
testfile.gpg: GPG encrypted data
$ 
$ cat decrypt.sh
#!/bin/bash
gpg --output testfile.txt --decrypt testfile.gpg

$ 
$ cat passphrase.txt
disneyland
$ 
$ . decrypt.sh <passphrase.txt

You need a passphrase to unlock the secret key for
user: "Alice"
2048-bit ELG-E key, ID 46972146, created 2009-07-18 (main key ID 53FD32A9)

gpg: encrypted with 2048-bit ELG-E key, ID 46972146, created 2009-07-18
      "Alice"
$ 
$ file testfile.*
testfile.gpg: GPG encrypted data
testfile.txt: ASCII text
$ 
$ cat testfile.txt
this is a test file
that I'd like to encrypt/decrypt
using gpg
$ 
$

tyler_durden
# 3  
Old 07-19-2009
As for GPG, there's been a lengthy thread here, with a lot of explanation.
# 4  
Old 07-19-2009
I real dont want to use expect because of portability issues.
No offense...but I realy dont undersatnd your example...I see what you are doing...but what are you trying to say?

for now I am using this line:
Code:
`echo 'thepassword | gpg --passphrase-fd 0 -d thefile.gpg`

but that only gets me around the gpg issue, but not the core of the question -> how to pass strings to a running peece of code?!

further question:

how do I put a file (its content whether text or binary) into a shell variable?
This right here is not working:

Code:
file=`echo 'thepassword | gpg --passphrase-fd 0 -d thefile.gpg`
file $file
FILETYPE=`file $file | cut -d " " -f 2`
echo "$FILETYPE"

souldn't file tell me something like this:

Code:
[UTF-8 Unicode text

# 5  
Old 07-19-2009
There isn't one well defined way of passing a password to a program. Some you can echo to, others won't allow that (ssh for example). gpg only allows it with the --passphrase-fd option.

As for your example: the file utility works on files. There's no option to read from a pipe. Better save the content to a temporary file, run file on it, and then read the content back into a variable with cat (or any other mechanism your shell might provide)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to pass password as a variable for sshpass authentication?

Using below below command i'm able to connect or authenticate server, In below command password contains special characters sshpass -v -p 'ASJBA%hs76)#' ssh -q -o ConnectTimeout=5 hostname But If I pass password as a variable I'm not able to connect or authenticate server, can you please help... (1 Reply)
Discussion started by: sam@sam
1 Replies

2. Shell Programming and Scripting

How to pass root password with su and command?

Hello, I have list of around 400 devices. I need to restart a service /etc/init.d/psap23.sh in all of them, but it should restart by root only. Those have some other kind of light Linux. There is no sudo package in that and we can't/shouldn't install. Direct root login is not allowed. I login... (5 Replies)
Discussion started by: solaris_1977
5 Replies

3. Shell Programming and Scripting

Pass the password to su in shell script

Hello, I am using below command but this is asking for tty c42dba {/home/oracle}: echo sersnp | su -c ggs standard in must be a tty Best regards, Vishal (4 Replies)
Discussion started by: admin_db
4 Replies

4. UNIX for Advanced & Expert Users

How to auto pass password in shell script !

Hi all, I have a simple script to check the CPU, Swap Memory and Hard Disk. But I can auto assign password in the script to automatic run it in crontab. Everytime when I run this script, it require to insert password like the message below : How can I solve this problem ? (2 Replies)
Discussion started by: cafecoc85
2 Replies

5. Shell Programming and Scripting

How to pass the password as input parameter to scp

Dear all Does anybody know how to pass the password as input parameter to scp or rsync in unix scripts? I have tried echo <password> | scp filename username@<ip address>:/filepath/ . But it does not work. BTW, I dont want to setup ssh trust between servers in this adhoc task. Regards,... (2 Replies)
Discussion started by: eldonlck
2 Replies

6. Shell Programming and Scripting

How to pass decrypted password to script

Hi Everybody, I am trying to write a script (ksh) to connect to oracle db via sqlplus. As I do not want the password to be in plain text, I've tried to use java to encrypt and decrypt it but I am not sure how can I pass the decrypted password to the script. Pls advise. Below is what I would... (1 Reply)
Discussion started by: Nick1971
1 Replies

7. Shell Programming and Scripting

Pass root password through script

I have several clients (over 120) connected to my server. I want to push some patch to all the client using a script which copies the file from the server to a specific path on the client and then installs it. But for installation of the patch, it needs to be done thorough root login on client.... (7 Replies)
Discussion started by: shahdeo
7 Replies

8. Shell Programming and Scripting

Not able to pass Username and Password in telnet session

I have created a shell script to telnet remote machine. Here is the problem I am not able to pass the login username and password to the telnet session. I have searched forum and got few other methods to achieve this. But I need to know what's wrong in the below script. username="root"... (2 Replies)
Discussion started by: uxpassion
2 Replies

9. Shell Programming and Scripting

SFTP - Pass password auti

ftp -i -n <<HERE open $IPADD user $USRNAME $PASS cd / get $FNAME close quit HERE Hi all the above script i used for ftp. How to modify same for sftp? thanks in advance (10 Replies)
Discussion started by: bullz26
10 Replies

10. UNIX for Dummies Questions & Answers

pass the password to SU??

hi, i have a lot of su in my script. and it keeps asking for a password every single time. how can i pass the password to su command? any setup i need to do? i used a redirect, not working. su -username - c "command" < "password" thanks for any help! (5 Replies)
Discussion started by: bikoyski
5 Replies
Login or Register to Ask a Question