Bash script - “tar czf …” command ignore parameters

被刻印的时光 ゝ 提交于 2019-12-31 06:12:12

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!