How to write a script for text file encryption?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to write a script for text file encryption?
# 1  
Old 08-28-2011
How to write a script for text file encryption?

Hi All,

I have zero knowledge in UNIX, so i desperately need the help from you guys.

I need a script which can encrypt all the text files in one shot in a source directory.
After all the text files are encrypted, they will be put into a separate folder.

Command involve:
gpg with -a, --armor

eg.
Before encyption:
/main/project/sorce/file1.txt
/main/project/sorce/file2.txt
/main/project/sorce/file3.txt

Before encyption:
/main/project/target/file1.txt.gpg
/main/project/target/file2.txt.gpg
/main/project/target/file3.txt.gpg
# 2  
Old 08-28-2011
You can process multiple files with the following option to gpg:

Code:
gpg -r "somename" --encrypt-files `ls /main/project/sorce/*.txt`

once you get the *.gpg files move them

Code:
mv /main/project/sorce/*.gpg /main/project/target/

If you want you can put the above 2 commands into a file and make it into a shell script, but not needed.
# 3  
Old 09-11-2011
Thanks.

How to make it into shell script?
Is there any script that is able to automatically encypt whenever there are new txt files are dropped into the /source folder?

Please advise.
# 4  
Old 09-11-2011
Sample code - the script handles one file at a time.
Enhance it for your need.

Code:
#!/bin/bash
#Script Name : encrypt.sh
#run the script in the background and forget about it i.e. ./encrypt.sh &
old_file_count=0
while true; do
  curr_file_count=`ls | wc -l`
  if [ $curr_file_count -gt $old_file_count ]; then
    old_file_count=$curr_file_count
    new_file=`ls -rt | tail -1`
    echo "New file found : $new_file : do whatever you want now"
    #gpg -r $new_file.gpg --encrypt-files $new_file
    #mv $new_file.gpg /where/ever/you/want
  fi
  #Change the sleep timer to your need
  sleep 5
done

You can also add this as a cronjob with necessary changes.

--ahamed

Last edited by ahamed101; 09-11-2011 at 05:44 AM..
# 5  
Old 09-12-2011
The following is our manual command to encypt those txt files in source folder:
gpg --verbose --armour --encrypt --recipient "IMS_L2" --output Jan_Payment.pgp Jan_Payment.txt

How can I integrate it into the new shell script?
# 6  
Old 09-12-2011
Code:
...
gpg --verbose --armour --encrypt --recipient "IMS_L2" --output $new_file.pgp $new_file.txt
...

Like this?

--ahamed
# 7  
Old 09-12-2011
Im testing this code in a development environment.
As far as i know, in the production it need a public key to do the encryption.
Where can i find the public key?
Is this the public key "IMS_L2"?

---------- Post updated at 07:32 AM ---------- Previous update was at 07:27 AM ----------

"
Code:
gpg :encryption of 'ls /home/taurus/project/source/*.txt failed:public key not found

"
This is one of the msg I encountered,

Last edited by pludi; 09-13-2011 at 04:41 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

How to write in other language in text/xml file by reading english text/xml file using C++?

Hello Team, I have 2 files.one contains english text and another contains Japanese. so i have to read english text and replace the text with Japanesh text in third file. Basically, I need a help to write japanese language in text/xml file.I heard wstring does this.Not sure how do i write... (2 Replies)
Discussion started by: SA_Palani
2 Replies

2. Shell Programming and Scripting

Need help to write a shell script to convert text file to excel file.

Hi Everyone, I want your help to write a script which will take text file as input and on the basis of delimiter ":"script will create excel sheet. Example input: IpAdress:InstanceName:Port:ServerName 10.255.255.1:abc:2232:xyz_abc Output should be an excel sheet like below: Column... (8 Replies)
Discussion started by: akabhinav18
8 Replies

3. Cybersecurity

File encryption tools with MAC address as an encryption key

Hi all, I'm looking for secure file encryption tools that use MAC address as encryption key. FYI, I'm using Red Hat Enterprise Linux OS. For example: when A wants to send file to B A will encrypt the file with B's computer MAC/IP address as an encryption key This file can only be decrypted... (2 Replies)
Discussion started by: sergionicosta
2 Replies

4. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

5. Shell Programming and Scripting

How to write text file data to excel using UNIX shell script?

Hi All, I have the requirement in unix shell script. I want to write the "ls -ltr" command out put to excel file as below. Input :text file data : drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x 2 apx aim 4096 Nov 29 18:40 drwxr-xr-x 5 root root 4096 Oct 2 12:26 drwxr-xr-x... (10 Replies)
Discussion started by: Balasankar
10 Replies

6. UNIX for Dummies Questions & Answers

Simple script to write new lines in a text file

Hello, I have a comma seperated data sheet with multiple fields of biological data. One column contains the ID name of the sample, where there could be more than one sample separated by a comma. I would like a script that reads this field, and for each sample ID, copies the entire line and writes... (18 Replies)
Discussion started by: torchij
18 Replies

7. Shell Programming and Scripting

how read specific line in a file and write it in a new text file?

I have list of files in a directory 'dir'. Each file is of type HTML. I need to read each file and get the string which starts with 'http' and write them in a new text file. How can i do this shell scripting? file1.html <head> <url>http://www.google.com</url> </head> file2.html <head>... (6 Replies)
Discussion started by: vel4ever
6 Replies

8. Programming

how to write Microsoft Access MDB file to a text file, using C ?

I'm in the UNIX environment. I'd like to read a Microsoft Access MDB file, and write the contents of that file into an ASCII text file. I want to write a C program to do this. Does anyone know if there's already source code out there that does this? Please advise. Thanks. (3 Replies)
Discussion started by: serendipity1276
3 Replies

9. UNIX for Dummies Questions & Answers

File encryption/Key encryption ????

My dilemma, I need to send, deemed confidential, information via e-mail (SMTP). This information is sitting as a file on AIX. Typically I can send this data as a e-mail attachment via what we term a "mail filter" using telnet. I now would like to somehow encrypt the data and send it to a e-mail... (1 Reply)
Discussion started by: hugow
1 Replies

10. UNIX for Advanced & Expert Users

encryption of text file for ftp

How can I encrypt a file before ftp'ing it. I am creating a text file abc.dat and I want to encrypt that file with same name and ftp it to a remote server. Please advise. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question