unix - Variables as commands in bash scripts -
I have a very simple bash script that any directory tars is encrypted to produce it, and writing then The resultant file segmentation In many small files, backup media does not support very large files.
There is not much experience with me bass scripting I believe that I point to quote your variables properly allow spaces in parameters I script is as follows:
#! / Bin / bash # This script tariffs the directory given, encrypts it, and transmits # in the given directory (possibly a USB key). 1 fi exit DIRECTORY = $ 1 BACKUP_DIRECTORY = $ 2 BACKUP_FILE = "$ BACKUP_DIRECTORY /` date +% Y-% m-% dT% H%: if [$ # -ne 2] then "` basename $ 0` DIRECTORY BACKUP_DIRECTORY use "echo \" $ BACKUP_FILE \ "" ENCRYPT_CMD = 'openssl des3 salt' echo '| $ ENCRYPT_CMD | $ SPLIT_CMD $ TAR_CMD "- M% S.backup`" TAR_CMD = "tar CV $ directory" SPLIT_CMD = "B 1024M Partition $ TAR_CMD | $ ENCRYPT_CMD | $ SPLIT_CMD says that "backed up" failed with this command running:
partition: "foo / 2009-04- 27T14-32-04. come back ": no such file or directory
I can fix by removing the quotes around it $ BACKUP_FILE where I Set $ SPLIT_CMD . But, if I have a location on the name of the backup directory, then it does not work. In addition, if I copy and paste the output directly from the terminal with the "echo" command then it works fine. Obviously there is nothing I do not understand about how to avoid Bash things.
After
just do not complete the variable, in order to recover the quoted arguments you may be quite upset .
In addition:
- Avoid using all the capital variable names in the script.
- Do not use backquote, instead use $ (...), this nest is better.
#! / Bin / bash if [$ # -A 2] "Usage: $ (originally $ 0) Directory 1 Exit BACKUP_DIRECTORY" fi directory = $ 1 backup_directory = $ 2 current_date = $ (date +% Y-% m -% dT% H) -% M-% S) backup_file = "$ {backup_directory} / $ {current_date} .backup" tar cv "$ directory" | Openssl des3 -salt | | Partition-B 1024m - "$ backup_file"
Comments
Post a Comment