matt
matt

Reputation: 11

tar file not archiving

I am doing the following in a shell script:

tar cvzf mytar.tgz *

It works fine when I run the shell script from a terminal. When it runs the shell script from a cron job using crontab it looks like it is archived because the tgz file is there but the filesize is nothing and when I untar it there is nothing there. However, when I run the shell script via terminal the tgz has a larger filesize and I can untar them.

Anyone know why it won't work via the cronjob?

Upvotes: 1

Views: 869

Answers (4)

Kyle Burton
Kyle Burton

Reputation: 27548

The other answers so far give good advice. Cron has a lot of special rules wrt what is allowed in the command. I have he most success when I make a simple shell script, and put it in $HOME/cron, chmox 755 it and put the full path to it in cron. Making sure to test the script - ensuring to cd'ing as necessary. Be aware that cron not only won't necessarily run the command from your home, but it will also likely have a different PATH and other environment settings will be missing.

Upvotes: 0

arkigos
arkigos

Reputation: 362

First, no need to be verbose in a cron.

Second, it looks like you are using relative pathing there. Consider using absolute paths, even for the tar command itself.

Last, which user is running the cron? Is there a potential for a permissions issue or a quota issue?

Upvotes: 0

Adam Liss
Adam Liss

Reputation: 48310

Try specifying the complete path to the files you want to archive:

tar cvzf mytar.tgz /path/to/your/files/*

Cron runs from a different directory from your $HOME.

Upvotes: 1

jwodder
jwodder

Reputation: 57590

What's the working directory of the cronjob process? If there's nothing in it, then the command will archive all of the nothing.

Upvotes: 0

Related Questions