问题
I have a simple bash script called script.sh
!#/bin/bash
tar czf /var/log/apache2/Backup_$(date "+%d-%m-%Y").tar.gz /var/log/apache2/ --exclude='backup*' --exclude='Backup*'
When I rund this line in SSH-Console, all works fine but when I run the .sh-script at linux console with bash ./script.sh
then the tar czf ...
command works but ignore the --exclude parameters
Whats wrong? I don't know... :/
回答1:
you have to use :
!#/bin/bash
tar -czf /var/log/apache2/Backup_`date "+%d-%m-%Y"`.tar.gz /var/log/apache2/ --exclude='backup*' --exclude='Backup*'
回答2:
try this one:
UPDATE
#!/bin/bash
tar -cZf /var/log/apache2/Backup_$(date +%Y%m%d).tgz.gz /var/log/apache2/ --exclude='backup*' --exclude='Backup*'
exclude is a pattern... see these helps: help1 help2 help3
来源:https://stackoverflow.com/questions/22146246/bash-script-tar-czf-command-ignore-parameters