1752754 Members
4869 Online
108789 Solutions
New Discussion юеВ

Re: cron & tar

 
SOLVED
Go to solution
Paul Sperry
Honored Contributor

cron & tar

here is my tar script I want cron to run.

#!/bin/sh
x="/some/path/$(date +%F)_mystuff.tar"
/bin/tar -cvf $x /path/to/backup

I know cron and shell are different, at
the command line it runs fine but in cron
it does nothing. Isn't this simple script
cron friendly?

TIA
9 REPLIES 9
Paul Sperry
Honored Contributor

Re: cron & tar

I take that back. At the command line it says:

/bin/tar: Removing leading `/` from member names


But it does work and create the tar
Paul Sperry
Honored Contributor

Re: cron & tar

Ok I simplified it, took the date out of the file name and removed the leading "/" from both paths

#!/bin/sh
x="some/path/mystuff.tar"
cd /
/bin/tar -cvf $x path/to/backup

Now no messages at command line and it works fine. But still does not work in cron. I took the date thing out but I REALLY do need it
Paul Sperry
Honored Contributor

Re: cron & tar

Some more strange facts. The cron log is not showing the CMD (/path/to/script.sh)
like it usually does for all my other cron jobs. It's just showing (root) RELOAD (cron/root)
Jared Middleton
Frequent Advisor

Re: cron & tar

Hi Paul,

Your initial example script works fine for me in cron (RHEL 4.6 ES, bash, vixie-cron-4.1-49.EL4).

I got a tar file that looks as expected and an email from cron (because output was not redirected):
Subject: Cron /home/myuserid/myscript

/bin/tar: Removing leading `/' from member names
/home/myuserid/testdata/
/home/muuserid/testdata/miscfiles
... etc ...

So, I'm not sure what your specific issue is, but wanted to give some feedback so you can focus on things other than the script itself.

Jared Middleton
Paul Sperry
Honored Contributor

Re: cron & tar

Hi Jared

Thanks for the feed back. I kind of thought the script was ok too. I didn't set this box up so there must be some funky cron setting that I am missing. At least I can rule the script out.

Thanks again
Stuart Browne
Honored Contributor

Re: cron & tar

How is it being called from Cron?

Is it a user-based crontab (i.e. crontab -u)? A system-based crontab (/etc/crontab, /etc/cron.d/, /etc/cron.{daily,weekly,monthly}/<script>) ?

If it's the first two, check the 'MAILTO' environment variable.

If it's one of the last 3, then check the MAILTO variable in '/etc/crontab'.

If it's a user-based crontab, once again, the MAILTO variable in there.
One long-haired git at your service...
Paul Sperry
Honored Contributor

Re: cron & tar

Hey guys,

First of all thanks for your input.
As you can see from my profile Iam
a HP-UX guy not a linux guy.
It turns out that my original script
would have worked but I was not
giving cron enough time to "reload".
That is when I was testing I would schedule
cron to execute the script about 2 minutes
after I edited the script. After hours of
googeling I re-edited my script to the original
and scheduled cron to run it 15 minutes later.
And guesss what...It worked. In HP-UX I allways
did a date command and then scheduled cron to execute
1 or 2 minutes later and it allways worked. But I
guess linux needs more time.

Silly me for wanting to test and being impatient.

Any comments are certinally welcome.

PS. I like to "bunny" all of my threads.
Jared Middleton
Frequent Advisor
Solution

Re: cron & tar

Don't blame linux. What distribution of linux and cron are you using? I mentioned mine earlier. I always set my jobs to run 2 minutes out (after checking date) just like you say you do... and I don't recall ever seeing the RELOAD message/problem.

From what I recall, cron checks for new crontabs AFTER each one minute iteration, so you do need to schedule at least 2 minutes out from the moment your crontab is saved... unless of course your job is set to execute EVERY minute (* * * * *).

Jared
Paul Sperry
Honored Contributor

Re: cron & tar

uname -a
Linux server.domain.com 2.6.9-42.0.3.EL #1 Mon Sep 25 17:14:19 EDT 2006 i686 i686 i386 GNU/Linux

Whatever that translates to.