Question

I have this command

tar -czf /var/log/apache2/logfile_backups/dBackup_$(date "+%d-%m-%Y").tar.gz /var/log/apache2/ --exclude=/var/log/apache2/logfile_backups --exclude='*.sh'

First, I run this command in a SSH-Console (Putty), everything works great!

Second, I write a bash-Script (myscript.sh)

#!/bin/bash
tar -czf /var/log/apache2/logfile_backups/dBackup_$(date "+%d-%m-%Y").tar.gz /var/log/apache2/ --exclude=/var/log/apache2/logfile_backups --exclude='*.sh'

And start this script in SSH-Console with bash ./myscript.sh, but the result at the end is not the same. The tar-command ignores the second --exclude parameter.

What's wrong? I think, a bash script is the same as a SSH-console like Putty.

No correct solution

OTHER TIPS

As an example I found on net:

a simple backup script would be:

#!/bin/bash          
OF=/var/my-backup-$(date +%Y%m%d).tgz
tar -cZf $OF /home/me/

So try to change your command to:

tar  -cZf /var/log/apache2/logfile_backups/dBackup_$(date +%Y%m%d).tgz.gz /var/log/apache2/ --exclude=/var/log/apache2/logfile_backups --exclude='*.sh'

1) What distros are you using?

2) Are you running the command and script exactly at one server or not?

3) Try chmod +x script.sh and then invoke it by saying ./scipt.sh

4) Specify tar version by saying tar --version

You said:

I think, a bash script is the same as a SSH-console like Putty.

Be sure that they are the same as each other but working with terminal over Linux is much easier

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top