Zip with Password


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zip with Password
# 1  
Old 12-22-2012
RedHat Zip with Password

Hi,

In my shell script I am using the zip command to zip the log files. The zip file is password protected. But there is a dicey.

I want the output as:
1) All files should be zipped including sub-directories' files
2) All files (individually) should be Password protected (may be common or different)
3) User should feed the password as input just once.

Condition 1 is met. But in Condition2 the sub-directory files are not password protected.Rather the sub-directory is password protected.

I used
Code:
zip -r -9 -m -P password  file_name.zip  *

Here password I handled in variable (condition 3) and without any interference zip command works. I tried using zip command option -e (as zip -r -e ...). But it prompts for password twice which is not recommended. Or is there any way to get the password from user as input and feed the same in run time when it prompts for Password while using -e option?

Please suggest.Smilie

Last edited by jim mcnamara; 12-22-2012 at 12:39 PM..
# 2  
Old 12-22-2012
Code:
cd /path/to/files
tar cvf /tmp/myarchive.tar .
zip -9 -P password zipfilename.zip /tmp/myarchive.tar

to extract:

Code:
unzip -P password zipfilename.zip
cd /path/to/restore/directory
# list the archive to find one file
tar tf /tmp/myarchive.tar | more
# restore one file
tar xvf /tmp/myarchive.tar  [EXACT filename]
# restore the whole archive
tar xvf /tmp/myarchive.tar

Point is: you should be using tar, then compressing.
# 3  
Old 12-24-2012
Thanks for the response, Jim. As you suggested, it worked.
But let know :
1) if we can use -e as option and the password can be fetched from any file and given as input in run time scenario?
# 4  
Old 12-24-2012
Use a here document:

Code:
zip -9 -e zipfilename.zip /tmp/myarchive.tar <<EOF
passwordhere
EOF

The last EOF goes in the leftmost column. You can use anything you want instead od EOF - !, PLPL, FOOO
- anything that is junk as far as the shell you use thinks about things.
# 5  
Old 12-25-2012
Hi Jim,

I tried but still am not meeting with what I want.
Could you let me know where I went wrong ...

Code :
#!/bin/sh
echo "zip file name "
read p0
echo "enter S Path"
read p1
echo " enter D path"
read p2
echo " Enter Password"
read p3
cd $p1
zip -r -9 -e /$p2/$p0.zip <<EOF
$p3
EOF

In Output :
Enter Password
zip
Enter password:
Verify password:

My point is : When I entered the password then why does it prompt again?
Please do help me.Smilie

Regards,
mkr
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Notable to use password option in zip command

zip -P abc -r FBE_SalesRepAccount_20170913125741.zip FBE_SalesRepAccount_20170913125741.txt zip error: Invalid command arguments (encryption not supported) zip -v Copyright (C) 1990-1999 Info-ZIP Type 'zip "-L"' for software license. This is Zip 2.3 (November 29th 1999), by Info-ZIP.... (1 Reply)
Discussion started by: alokjyotibal
1 Replies

2. UNIX for Dummies Questions & Answers

Zip a file with password

Hi, newbie to Linux, is there another way to zip a file with a password other than using 'zip' command? (7 Replies)
Discussion started by: mined
7 Replies

3. UNIX for Dummies Questions & Answers

password protect a CSV file: better solution than ZIP password?

Hi We send *.csv with sensitive data to our customers. Our customers open those files with Excel. A new requirement is that we password protect those CSV files. I thought to pack them with ZIP and assign a password to the archive. But Solaris 10 can't encrypt ZIP files. $ zip -P... (12 Replies)
Discussion started by: slashdotweenie
12 Replies

4. AIX

How to zip file in AIX with password.

Hi Guru, I have assignment to create script to compress file as .ZIP with password. I don't know the command line in AIX. It's very new for me. I'm try to use zip or tar but I don't have any option for encrypt with password. Please kindly suggest me. Thank you very much. Multidev (7 Replies)
Discussion started by: multidev
7 Replies

5. Shell Programming and Scripting

Password protect a zip file

Hi, I'm working on Solaris 9 and i need to unzip a password protected zip, which i can do using zip -Ppassword filename however when i have done what i need to do with the file is to zip the file back up with a password. Zip on my system is version 2.3 and does not support this? How can... (0 Replies)
Discussion started by: Pablo_beezo
0 Replies

6. UNIX for Dummies Questions & Answers

Zip file with password protection

I am trying to zip a file with password protection. I have read all or atleast most of the threads on the website, but couldn't come up with a solution. I am running ZIP version 2.3 on HP-UX but I dont see the -P (password) option. I read somewhere that free versions of zip don't come with... (5 Replies)
Discussion started by: pintu
5 Replies

7. UNIX for Dummies Questions & Answers

Syntaxt to zip a file with password protection

Hi Experts, I am an SAP ABAP developer and compleatly stranger to unix and I need a help to extend a small peice of code. Our requirement is to zip a file with password protection in a specified directory. Following is the code I am using to zip a file ZZZZ.TXT. Here YYYY = is the path... (3 Replies)
Discussion started by: veeru4all
3 Replies

8. UNIX for Dummies Questions & Answers

Zip and password protect non-interactively

I'm wondering if there is a way to zip a file and password protect it non-interactively. zip -e will prompt for a password but I don't want a prompt. This needs to be done automatically as part of a shell script. I'm using the zip command because the will be unzipped by a Windows machine. ... (1 Reply)
Discussion started by: savage66
1 Replies

9. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

10. UNIX for Advanced & Expert Users

Does unix has password protection for zip files?

How to set password in zip files under unix? There are password protection available in various os. Does unix has password protection for zip files? Is zip and gzip command has it? (6 Replies)
Discussion started by: p_prathaban
6 Replies
Login or Register to Ask a Question