zip -re <Filename>

noman1977

New Member
Joined
Apr 27, 2021
Messages
1
Reaction score
0
Credits
13
Hi,
I have one script which is daily run and create the backup file, once the backup is complete i have run manually zip -re <filename> . This command will ask the password. i want once my script will complete the file which have created from backup it should be zip with password. I dont want to write password on script file. Or is there any faclity to put the encrypted password on script file. ?
 


You can create a MD5 string or hash of the password and use that in the script, you can see here how it's done and here or you can use openssl.
 
Last edited:
Or maybe something like this:
Encpass.sh uses openssl for encyption/decrytion of passwords.

Use the encpass script to encrypt a password and save it to a file.
Make sure that the encrypted file has 400 permissions (Read only for owner). That way, only scripts that are running as you can open the file.

Edit your backup script to source the encpass script, so you have its get_secret function available to you. Then you can use a sub-shell to decrypt the password from the file and pass the unencrypted password to the zip command.

Something like this:
Bash:
# source encpass.sh, so we can decrypt the password
. /path/to/encpass.sh

# Rest of your script......
#.......

# use a sub-shell to get the decrypted password
# via encpass.sh's get_secret function
# and substitute that into the zip command.
zip -reP ${get_secret} <filename>
Something like that should work...... I think!

Notes:
In the above - replace /path/to/encpass.sh with the path to wherever you put the encpass script.
Also note, to source the script in your backup script - we are using bash's . (dot/period) builtin, which is equivalent to using the source command.
So there is a space between . and /path/to/encpass.sh.
So it's . /path/to/encpass.sh and NOT ./path/to/encpass.sh

Also replace <filename> with the path to the file/directory you are zipping/encrypting.
 
Last edited:

Members online


Latest posts

Top