Expext script reading a crypted file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expext script reading a crypted file
# 1  
Old 08-24-2006
Expect script reading a crypted file

People, I really have two problems in one. Basicly "option 2" is the one I wish to persue but "option 1" will do for now....

Option 1
I have an expect script. I would like it to read (open ) a crypted file with out creating a decrypted file from the source (crypted file) then open and read the flat file.... any ideas....?

Option 2
I can do this from with in a standard UNIX script - no problem
ie (eval `crypt key </tmp/filename`)

Question.....
How do I (or can I) execute "expect" commands from with in the shell script (Without running a third external expect scrpit) and pass the shell varibales required to the expect code from with in the shell script?

Back ground.
The crypted file format is thus....
userid="myid"
password="mypass"
commnet="This is a comment"

Thanks
Andrek

Last edited by Andrek; 08-28-2006 at 12:56 AM.. Reason: typo in heading
# 2  
Old 08-25-2006
Assuming I got what your problem is:
Code:
#!/bin/ksh
echo "password to encrypted file:\c"
stty noecho
read pass
stty echo
value=`crypt "$pass" < passwordfile | pr`
user=`echo "$value" | grep 'username=' | awk -F= '{print $2}'`
userpasswd=`echo "$value" | grep 'password=' | awk -F= '{print $2}'`
#....... you now have the user's username & password

This way the password to decrypt the file is not in any script, nor does is it on the commandline to allow ps -ef to show it.

If you have to use expect, then create the expect script as a here document
with the password input varaible -- input the same as part of the code above. A priori, expect looks like a messier solution overall. But I dunno what your requirements are.
# 3  
Old 08-27-2006
Hi, Thanks for the info. I can get the UserID and Password from the crypted file inside a unix sh (/usr/bin/ksh) because the crypted file format is....
Userid="xxx"
passwd="aaa"
comments="bbb ccc ddd"
etc

the eval 'crypt key <$cryptfile command will do that for me.

ie $Userid is created and set to xxx.

The problem is.

The old way of doing things is an expect script opens the $userfile and reads gets the password and userid etc etc. This leaves a normal file on the system with a userid and password available to been seen. (The file is deleted once all processing has been completed)

The new way is to have the $userfile crypted so that if the file is left behind on the system no one can view the userid and password details.

The system in question is on a secure (outside the DMZ) , thus direct login is strictly is limited and my task is to create a script that will allow 1st level UNIX staff to create secure ftp logins on that server with out logging.

It all works fine but we need to work with a crypted file. Therefor my expect skills are low and I need to complete this task very soon.

Anymore ideas?
# 4  
Old 08-27-2006
Worked it out.....The answer was obvious....

#!/bin/usr/ksh
Do some shell stuff
eval `crypt $key <$cryptfilename`

/usr/bin/expect <<EOF
do expect stuff
send "$UserID" # Got this from ksh shell
send "$Passwd" # Got this from ksh shell

exit;
EOF

Do other shell stuff
Now we back in ksh script

I am closeing this thread
:-)
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh Script, Reading A File, Grepping A File Contents In Another File

So I'm stumped. First... APOLOGIES... my work is offline in an office that has zero internet connectivity, as required by our client. If need be, I could print out my script attempts and retype them here. But on the off chance... here goes. I have a text file (file_source) of terms, each line... (3 Replies)
Discussion started by: Brusimm
3 Replies

2. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

3. Programming

Expext Script excution problem..

Hey Guys , iam trying to match to string in TCL scripts but it not working . Its only working true condition to print yes.. When condtion fail then even it prints YES Any suggestion this ?? if {} { puts"yes" ... (3 Replies)
Discussion started by: hackerdilli
3 Replies

4. UNIX for Dummies Questions & Answers

UNIX script for reading a file and creating another file

Hi, I am a beginner in scripting...I have to do a script where I have to read a file which has list of job names, line by line and for every line execute a dsjob command to find the log details of the job and extract only the start time of the job, if it is greater than jan 01 2008 and create... (1 Reply)
Discussion started by: Vijay81
1 Replies

5. Shell Programming and Scripting

Script for reading .csv file

Can someone please help me to write script for following scenario : 1> script should read a input .csv file of format : EmpName, PF, Leave, Basic ,HRA 2> another config file ( may be again a .csv file ) has format EmpName and EmpID 3> script should read another config file for each EmpName in... (3 Replies)
Discussion started by: creativeworld
3 Replies

6. Shell Programming and Scripting

Reading file names from a file and executing the relative file from shell script

Hi How can i dynamically read files names from a list file and execute them from a single shell script. Please help its urgent Thanks in Advance (4 Replies)
Discussion started by: anushilrai
4 Replies

7. UNIX for Dummies Questions & Answers

script to reading a file

hi, I have a file containing names, say n number of names, sample file robin smith dallas frey cook all these names are in a file name called names.txt and it is placed in a directory called /data/names all i want is to write a script, which will read from the file and gives the... (3 Replies)
Discussion started by: vasikaran
3 Replies

8. Programming

Reading a file into a C++ script

Hi, I'm trying to read a file in with and assigne the stream to a char * type. I've manged it using the cin.get returning type char, but am having run-time problems returning a char *. For example, char *pStream = "file.txt"; ifstream from(pStream); from.open(pStream); ... (1 Reply)
Discussion started by: Breen
1 Replies
Login or Register to Ask a Question