0

So I followed the solution here: command to zip multiple directories into individual zip files

and I added -er to the command however as I expected, I need to enter the password for every loop operation, i.e for every folder that gets zipped.

How can I automate the password part? I want to use the same password for all zipped files.

Thanks

EDIT: It would be great if I can have all the output zip files created in another directory

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
Tarek
  • 125

1 Answers1

0

Instead of the -er flag, you could use the -P flag - it expects the password to follow.

-P password
   --password password
          Use password to encrypt zipfile entries (if any).  THIS IS INSE-
          CURE!   Many  multi-user  operating systems provide ways for any
          user to see the current command line of any other user; even  on
          stand-alone  systems  there  is  always  the threat of over-the-
          shoulder peeking.  Storing the plaintext password as part  of  a
          command  line  in  an  automated script is even worse.  Whenever
          possible, use the non-echoing, interactive prompt to enter pass-
          words.   (And  where  security  is  truly  important, use strong
          encryption such as Pretty Good Privacy instead of the relatively
          weak standard encryption provided by zipfile utilities.)

Note it is insecure because the password is displayed on the command line and potentially viewable by others looking at the process tree.

If that's not acceptable, look into using the expect utility.

http://expect.sourceforge.net/

  • Worked well however I'm not able to use special characters in my password like !@#$ I tried this https://superuser.com/questions/163515/bash-how-to-pass-command-line-arguments-containing-special-characters I tried putting the password in " " and ' ' or even putting a / before every special character but it doesn't work. The password either comes out empty or different than what I wanted. – Tarek Jun 09 '17 at 21:53
  • This is how my command looks like: for i in */; do zip -r "${i%/}.zip" "$i" -p "mypassword!@#$" ; done – Tarek Jun 09 '17 at 21:54
  • Any other ideas? – Tarek Jun 11 '17 at 08:04