Shell Script - Bash and Expect

Error out while encrypting of list of text files in a directory.

Please check the below.

For encrypting one file.. it is working...

-bash-4.1$ ./TestWorking1.sh
spawn /opt/PGP/pgp -e +force TestScript2.txt xyzsolutions (Integrations) <intadmin@xyzsolutions.com>
Pretty Good Privacy(tm) Version 6.5.8
(c) 1999 Network Associates Inc.
Uses the RSAREF(tm) Toolkit, which is copyright RSA Data Security, Inc.
Export of this software may be restricted by the U.S. government.



Recipients' public key(s) will be used to encrypt.

Key for user ID: xyzsolutions (Integrations) <intadmin@xyzsolutions.com>
1024-bit DSS key, Key ID 0xD4D727C0, created 2004/01/15
WARNING:  Because this public key is not certified with a trusted
signature, it is not known with high confidence that this public key
actually belongs to: "xyzsolutions (Integrations) <intadmin@xyzsolutions.com>".

Are you sure you want to use this public key (y/N)?y

Ciphertext file: TestScript2.txt.pgp


-bash-4.1$ more TestWorking1.sh
#!/usr/bin/expect -f
cd /export/home/oradev/scripts
spawn /opt/PGP/pgp -e +force TestScript2.txt  "xyzsolutions (Integrations) <intadmin@xyzsolutions.com>"
expect "Are you sure you want to use"
send "y\n"
expect "$"

===============================

For encrypting multiple files.. it is not working...


-bash-4.1$ ./TestWorking2.sh
./TestWorking2.sh: line 6: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestWorking2.sh: line 8: send: command not found
couldn't read file "$": no such file or directory
./TestWorking2.sh: line 10: EOD: command not found
./TestWorking2.sh: line 6: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestWorking2.sh: line 8: send: command not found
couldn't read file "$": no such file or directory
./TestWorking2.sh: line 10: EOD: command not found
./TestWorking2.sh: line 6: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestWorking2.sh: line 8: send: command not found
couldn't read file "$": no such file or directory
./TestWorking2.sh: line 10: EOD: command not found
./TestWorking2.sh: line 6: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestWorking2.sh: line 8: send: command not found
couldn't read file "$": no such file or directory
./TestWorking2.sh: line 10: EOD: command not found

-bash-4.1$ more TestWorking2.sh
#!/bin/bash
cd /export/home/oradev/scripts
for i in `ls *.txt`
do
#!/usr/bin/expect -f << EOD
spawn /opt/PGP/pgp -e +force $i "xyzsolutions (Integrations) <intadmin@xyzsolutions.com>"
expect "Are you sure you want to use"
send "y\n"
expect "$"
EOD
done;
-bash-4.1$

Please help.
Anand TAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
#!/bin/bash
cd /export/home/oradev/scripts
for i in `ls *.txt`
do
/usr/bin/expect << EOD
spawn /opt/PGP/pgp -e +force $i "xyzsolutions (Integrations) <intadmin@xyzsolutions.com>"
expect "Are you sure you want to use"
send "y\n"
expect "$"
EOD
done;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Anand TAuthor Commented:
Perfect.. Thanks a lot.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.