unzip password protected zip in unix - shell

I need to create a shell script wherein I will unzip a password protected zip file. I know the password, and need to automate the unzip process.
How can I achieve this using Unix shell scripting?

unzip -P your-password zipfile.zip
man unzip
-P password
use password to decrypt encrypted zipfile entries (if any). THIS IS INSECURE! 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 passwords. (And where
security is truly important, use strong encryption such as Pretty Good
Privacy instead of the relatively weak encryption provided by standard
zipfile utilities.)

In Ubuntu, I've to install 7zip (7z) archive tool using following command:
sudo apt-get install p7zip-full
Then, you can use Ubuntu's default Archive Manager to unzip the password protected zip files

I ran into problem using unzip saying need PK compat. v5.1 (can do v4.6).
Installed p7zip instead and unzipped using following command:
7z x archive.zip -ppassword

To unzip multiple password protected files, this command WILL NOT WORK
unzip -P PASSWORD *.zip
To make it work, you need to include the *.zip in quotes because whenever you use a wildcard (*), the shell itself will expand that and pass the results to the program. This is because, unlike most programs in UNIX, unzip cannot take more than one file at a time.
Read more here https://chrisjean.com/unzip-multiple-files-from-linux-command-line/.
Therefore, to unzip multiple protected files, use this
unzip -P PASSWORD '*.zip'

Please follow bellow instruction, i have solved same problem by following these steps.
sudo apt install p7zip-full
7z x example.zip
it will ask password for your zip file, provide password and let the process complete
Visit the following URL: For more details

Related

Need to create/delete text file in Unix box from windows

I have a requirement where i need to create and delete a text file on unix from my windows server where i have informatica installed.
Using workflow i was able to place file in unix but not able to find a way to delete already existing file.
Also the client does not want us to download any additional software like putty on windows server.
Please feel free to ask for more information if required.
if you are able to drop .sh (shell script) and execut it on unix then you can do that with "rmdir yourfolder" command, if you folder has andything under then you will need to use "rm -r yourfolder", if files inside the folder have any dependicies you need to use "rm -rf yourfolder".
Just make sure that you will navigate to the correct folder where you are deleting things.
Br, Aljaž.
Use Command Task in Informatica Workflow to invoke syntax mentioned by #Aljaz

wget - how to download all files that only include "480p" using wget from http server?

I want to download all files from a http server like:
http://dl.mysite.com/files/
and I also want to go inside each folder inside that folder.
But I do want to download only those files that have "480p" in their name.
What is the easiest solution for that using wget?
edit:
I want to have that script to be run each night from 2am to 6am to sync those files from that server to my PC.
The following wget command should work with the following flags:
wget -A "*480p*" -r -np -nc --no-check-certificate -e robots=off http://dl.mysite.com/files/
Explanation:
-A "480p" your pattern
-r, recursively recursively look through the folders
-np, --no-parent ignore links to a higher directory
-nc, --no-clobber If a file is downloaded more than once in the same directory, Wget’s behavior depends on a few options, including ‘-nc’. In certain cases, the local file will be clobbered, or overwritten, upon repeated download. In other cases it will be preserved.
--no-check-certificate Don’t check the server certificate against the available certificate authorities.
-e, --execute command A command thus invoked will be executed after the commands in .wgetrc
robots=off robot exclusion
More information on wget flags can be found at the official GNU manual page: https://www.gnu.org/software/wget/manual/wget.html
With regards to it being run once per day, you may want to read up on Cron jobs. Taken from the documentation page at: https://help.ubuntu.com/community/CronHowto
A crontab file is a simple text file containing a list of commands meant to be run at specified times. It is edited using the crontab command. The commands in the crontab file (and their run times) are checked by the cron daemon, which executes them in the system background.
So basically you need to put your wget command into a file, and set the cron to run this file at the specified time.
Note: Windows does not have a native implementation of Cron, but you can achieve the same effect using the Windows Task Scheduler.

Cygwin to use my windows username in path?

I'm writing a script where Cygwin needs to cp a file from my desktop.
cp /cygdrive/c/Users/<username>/Desktop/file /tmp/file
How can I make Cygwin get my or the username of the person who is currently running it?
I found it in a different answer,
The profile of the current user is $USERPROFILE.
Putting them together it becomes:
cp $USERPROFILE/Desktop/file /tmp/file

Linux / Windows Shell Scripting to Unlock PGP File

I have a sequence of scripts which downloads PGP files from a FTP server. I then unzip these files with a private key using PGPKeys. The unzipped files are then picked up by a SQL Server job which appends the data onto our database. I'd like to automate the entire process. Is there anyway to unzip a PGP locked file using shell scripting (either Linux or Windows)?
That's a perfect task to automize, I can help you in Linux.
First you can use wget to download a file
wget ftp://website.com/yourpgparchive.zip
If your ftp website requires authenticated access use
wget --ftp-user=USER --ftp-password=PASSWORD ftp://ftp.site/archive.zip.pgp
Then you need gpg (the open source PGP implementation) to decrypt the file
gpg -o file.zip -d file.zip.gpg
(If you need some suggestion on how to import keys and get started with gpg check here)
Then you can just unzip the file with
unzip file.zip
You may need to install gnupg and unzip from your package manager.
Yes, GPG. In your case, it's just gpg -d filename (or just gpg -d to read from stdin).
And, what you probably wanted to say is decrypt instead of unzip and encrypted instead of locked.

What does "download or create" mean in a tofrodos context?

I keep seeing this phrase "download or create" in tutorials right after tofrodos. What would be an example of how to download or create? I just get stuck in
^
^
^
mode.
apt-get -y install tofrodos
Download or create ZPX_ubuntu_12-04_auto_installer.sh
The author means you need to transfer the "ZPX_ubuntu_12-04_auto_installer.sh" shell script to the server, and if necessary, change to the directory you saved the script in using the cd command, before entering the commands below:
fromdos ZPX_ubuntu_12-04_auto_installer.sh
chmod +x ZPX_ubuntu_12-04_auto_installer.sh
./ZPX_ubuntu_12-04_auto_installer.sh
He seems to be referring to a particular script included in a .zip file posted on a web forum.
You may be able to download the .zip file to your computer, extract it, and then use the sftp or scp program to transfer just the shell script to the server. Alternatively, you could use wget or curl to download the .zip file to the server and then the unzip command to unzip it.
A graphical SFTP client like FileZilla may help for the former approach. The Firefox add-on cliget may help for the latter, especially because the file is hosted on a password-protected web forum.
fromdos is just a utility program to convert a text file from DOS/Windows format to Unix format by stripping out all the carriage return characters. Perhaps using this command is necessary because the author of the script used a Windows text editor or an ASCII-mode FTP transfer before zipping up the file. Of course, you need the file on the server if you are trying to run the command on the server.

Resources