Re: [gentoo-user] Script to tar.tgz /etc, works run manually, broken when run from cron

2014-04-01 Thread Tanstaafl

On 3/31/2014 10:43 AM, Daniel Frey djqf...@gmail.com wrote:

You need to use the full path to commands in your script or set an
environment variable. In my case using full paths to executables was enough.


Bingo... thanks Daniel!

Now to figure out why one of my remote systems is sending the cron email 
results and the other isn't...




Re: [gentoo-user] Script to tar.tgz /etc, works run manually, broken when run from cron

2014-03-31 Thread Neil Bothwick
On Mon, 31 Mar 2014 07:01:48 -0400, Tanstaafl wrote:

 I have a script that simply performs some backups. The commands are
 like this:
 
 # perform tar.tgz backup of /etc
 tar -czpvf $BKUP_DIR_etc/$BKUP_DateTime-dev-ecat-etc.tgz /etc
 
 When I run this script manually, it does what it is supposed to, and
 the resulting file is about 500K.
 
 When it runs from cron (roots crontab), it results in a 20 byte (empty) 
 file.

You're running tar with -v so it should produce output no matter what it
does. Is that mailed to you? What does it say?

You could add set -x at the start of the script for an even more
verbose report.


-- 
Neil Bothwick

Did you know that eskimos have 17 different words for linguist?


signature.asc
Description: PGP signature


Re: [gentoo-user] Script to tar.tgz /etc, works run manually, broken when run from cron

2014-03-31 Thread Helmut Jarausch

On 03/31/2014 01:01:48 PM, Tanstaafl wrote:

Hi all,

Ok, this is really irritating me...

I have a script that simply performs some backups. The commands are  
like this:


# perform tar.tgz backup of /etc
tar -czpvf $BKUP_DIR_etc/$BKUP_DateTime-dev-ecat-etc.tgz /etc

When I run this script manually, it does what it is supposed to, and  
the resulting file is about 500K.


When it runs from cron (roots crontab), it results in a 20 byte  
(empty) file.


So what am I missing/doing wrong?



This is what I do when debugging such things

put

echo $BKUP_DIR_etc/$BKUP_DateTime-dev-ecat-etc.tgz /tmp/cron.LOG
into an executable script and run it with
at now+1minute
and check /tmp/cron.LOG

perhaps one of $BKUP_DIR_etc or $BKUP_DateTime-dev-ecat-etc
isn't know in that environment

Helmut




Re: [gentoo-user] Script to tar.tgz /etc, works run manually, broken when run from cron

2014-03-31 Thread Tanstaafl

On 3/31/2014 7:13 AM, Neil Bothwick n...@digimed.co.uk wrote:

On Mon, 31 Mar 2014 07:01:48 -0400, Tanstaafl wrote:

I have a script that simply performs some backups. The commands are
like this:

# perform tar.tgz backup of /etc
tar -czpvf $BKUP_DIR_etc/$BKUP_DateTime-dev-ecat-etc.tgz /etc

When I run this script manually, it does what it is supposed to, and
the resulting file is about 500K.

When it runs from cron (roots crontab), it results in a 20 byte (empty)
file.


You're running tar with -v so it should produce output no matter what it
does. Is that mailed to you? What does it say?


I don't have these mailed to me, but like I said, it absolutely does 
produce output - the problem is, when run from cron, the resulting file 
is only 20 bytes (empty), when I run the exact same script manhually, it 
produces a file of about 500K that containes the contents of /etc..


On 3/31/2014 7:27 AM, Helmut Jarausch jarau...@igpm.rwth-aachen.de wrote:
 perhaps one of $BKUP_DIR_etc or $BKUP_DateTime-dev-ecat-etc
 isn't know in that environment

They are - see above...



Re: [gentoo-user] Script to tar.tgz /etc, works run manually, broken when run from cron

2014-03-31 Thread Neil Bothwick
On Mon, 31 Mar 2014 08:01:03 -0400, Tanstaafl wrote:

  You're running tar with -v so it should produce output no matter what
  it does. Is that mailed to you? What does it say?  
 
 I don't have these mailed to me, but like I said, it absolutely does 
 produce output - the problem is, when run from cron, the resulting file 
 is only 20 bytes (empty), when I run the exact same script manhually,
 it produces a file of about 500K that containes the contents of /etc..

So you have no idea what output the script is producing when run from
cron? Not a good plan when it is not working :(

When a script runs from the terminal but not from cron it is almost
always because of a difference in the environments, but without seeing
its output we can only guess at the problem.


-- 
Neil Bothwick

- How many surrealists does it take to change a light bulb?
- Two: one to hold the giraffe, the other to fill the bathtub with
  lots of brightly colored machine tools.


signature.asc
Description: PGP signature


Re: [gentoo-user] Script to tar.tgz /etc, works run manually, broken when run from cron

2014-03-31 Thread Daniel Frey
On 03/31/2014 04:01 AM, Tanstaafl wrote:
 Hi all,
 
 Ok, this is really irritating me...
 
 I have a script that simply performs some backups. The commands are like
 this:
 
 # perform tar.tgz backup of /etc
 tar -czpvf $BKUP_DIR_etc/$BKUP_DateTime-dev-ecat-etc.tgz /etc
 
 When I run this script manually, it does what it is supposed to, and the
 resulting file is about 500K.
 
 When it runs from cron (roots crontab), it results in a 20 byte (empty)
 file.
 
 So what am I missing/doing wrong?
 

You need to use the full path to commands in your script or set an
environment variable. In my case using full paths to executables was enough.

i.e.

# perform tar.tgz backup of /etc
/bin/tar -czpvf $BKUP_DIR_etc/$BKUP_DateTime-dev-ecat-etc.tgz /etc

Dan




Re: [gentoo-user] Script to tar.tgz /etc, works run manually, broken when run from cron

2014-03-31 Thread Alan McKinnon
On 31/03/2014 13:01, Tanstaafl wrote:
 Hi all,
 
 Ok, this is really irritating me...
 
 I have a script that simply performs some backups. The commands are like
 this:
 
 # perform tar.tgz backup of /etc
 tar -czpvf $BKUP_DIR_etc/$BKUP_DateTime-dev-ecat-etc.tgz /etc
 
 When I run this script manually, it does what it is supposed to, and the
 resulting file is about 500K.
 
 When it runs from cron (roots crontab), it results in a 20 byte (empty)
 file.
 
 So what am I missing/doing wrong?
 
 

It's almost always the same two things that cause this:

1. cron doesn't give you an environment so there's no $PATH. Other
posters covered this nicely.

2. I had this one just last week in fact - pwd is not what you think it
is. In cron it ends up being / so the solution was again to use full
paths. In my case, I had a config file listed on the command line.



-- 
Alan McKinnon
alan.mckin...@gmail.com