From a Unix viewpoint, running from cron does not set the environment
the same as with an interactive session. I have sometimes had to set
TERM=vt100 (or whatever) and other environment variables to get things
to run from cron.

One trick it to capture your environment to a file, edit out what you
know won't matter and add the rest to the top of your script:

        env > env.out
        vi env.out
        
Add
        . env.out

To script.

-----Original Message-----
From: G.W. Haywood [mailto:[EMAIL PROTECTED] 
Sent: Monday, June 19, 2006 5:53 AM
To: cygwin@cygwin.com
Subject: 1.5.19: tar runs normally from command line but terminates
early when run from crontab

Hi there,

This is my first installation of cygwin, and I'm not very familiar
with W2000 (server or otherwise).

Using ssh from a remote machine I log onto a Windows 2000 server which
is running a freshly installed cygwin.  The recommended settings were
used in the installation and in addition to the defaults, a few extra
packages were installed.  (Although I couldn't find ntpd anywhere...:)

On my local (Linux) box I get a bash prompt from the W2k server:

[EMAIL PROTECTED] ~
$

On the W2k server there are two physical devices in a simple RAID
array arranged as one logical drive.  I want to back up some files
from one of the Windows directories on this logical drive into a file
e.g. in the Administrator account's cygwin /home directory located on
the same logical device.  Later, when I have the file, I will copy it
to a remote machine.

To create the file I will use tar.  A simple tar command works when it
is run from the Administrator's command line (either in the foreground
or the background) but fails when run from the Administrator account's
crontab.

When run from the command line the job works whether gzip compression
is used or not, and when run from the crontab it fails also whether
compression is used or not, so I don't think it's anything to do with
pipes and DOS/Unix line endings.

It looks like I'm missing something here.  What is it?

------------------------------------------------------------------------
--------------------------------------------------------------------
The version of cygwin (installed on 16 June 2006) is: CYGWIN_NT-5.0
1.5.19(0.150/4/2) 2006-01-20 13:28

Process list:
------------------------------------------------------------------------
--------------------------------------------------------------------
[EMAIL PROTECTED] ~
$ ps -aelW
      PID    PPID    PGID     WINPID  TTY  UID    STIME COMMAND
        8       0       0          8    ?    0 20:24:48 *** unknown ***
      184       0       0        184    ?    0   Mar 18
\SystemRoot\System32\smss.exe
      204       0       0        204    ?    0   Mar 18
\??\C:\WINNT\system32\winlogon.exe
      256       0       0        256    ?    0   Mar 18
C:\WINNT\system32\services.exe
      268       0       0        268    ?    0   Mar 18
C:\WINNT\system32\lsass.exe
      464       0       0        464    ?    0   Mar 18
C:\WINNT\system32\svchost.exe
      520       0       0        520    ?    0   Mar 18
C:\WINNT\system32\spoolsv.exe
      724       0       0        724    ?    0   Mar 18
C:\WINNT\System32\msdtc.exe
      844       0       0        844    ?    0   Mar 18
C:\WINNT\system32\Dfssvc.exe
      864       0       0        864    ?    0   Mar 18
C:\WINNT\System32\svchost.exe
      892       0       0        892    ?    0   Mar 18 C:\Data\Program
Files\Autodesk Network License Manager\lmgrd.exe
      916       0       0        916    ?    0   Mar 18
C:\WINNT\System32\ismserv.exe
      928       0       0        928    ?    0   Mar 18
C:\WINNT\System32\llssrv.exe
      976       0       0        976    ?    0   Mar 18 C:\Program
Files\Network Associates\Common Framework\FrameworkService.exe
     1060       0       0       1060    ?    0   Mar 18 C:\Program
Files\Network Associates\VirusScan\Mcshield.exe
     1088       0       0       1088    ?    0   Mar 18 C:\Program
Files\Network Associates\VirusScan\VsTskMgr.exe
     1096       0       0       1096    ?    0   Mar 18 C:\Data\Program
Files\Autodesk Network License Manager\adskflex.exe
     1184       0       0       1184    ?    0   Mar 18
C:\WINNT\system32\ntfrs.exe
     1252       0       0       1252    ?    0   Mar 18
C:\PVSW\BIN\NTBTRV.EXE
     1312       0       0       1312    ?    0   Mar 18
C:\WINNT\system32\regsvc.exe
     1316       0       0       1316    ?    0   Mar 18
C:\PVSW\BIN\NTDBSMGR.EXE
     1328       0       0       1328    ?    0   Mar 18
C:\WINNT\System32\locator.exe
     1340       0       0       1340    ?    0   Mar 18
C:\WINNT\system32\MSTask.exe
     1412       0       0       1412    ?    0   Mar 18
C:\WINNT\System32\WBEM\WinMgmt.exe
     1424       0       0       1424    ?    0   Mar 18
C:\WINNT\system32\svchost.exe
     1436       0       0       1436    ?    0   Mar 18
C:\WINNT\System32\dns.exe
     1448       0       0       1448    ?    0   Mar 18
C:\WINNT\System32\inetsrv\inetinfo.exe
     1944       0       0       1944    ?    0   Mar 18
C:\WINNT\Explorer.EXE
     2012       0       0       2012    ?    0   Mar 18
C:\WINNT\System32\svchost.exe
     2156       0       0       2156    ?    0   Mar 18
C:\WINNT\system32\atiptaxx.exe
     2168       0       0       2168    ?    0   Mar 18
C:\WINNT\SOUNDMAN.EXE
     1904       0       0       1904    ?    0   Mar 18
C:\WINNT\system32\BacsTray.exe
     2196       0       0       2196    ?    0   Mar 18 C:\Program
Files\Network Associates\VirusScan\SHSTAT.EXE
     2212       0       0       2212    ?    0   Mar 18 C:\Program
Files\Network Associates\Common Framework\UpdaterUI.exe
     2244       0       0       2244    ?    0   Mar 18 C:\Program
Files\Silicon Image\SiISATARaid\SATARaid.exe
     1540       0       0       1540    ?    0   Mar 18
C:\WINNT\system32\wuauclt.exe
      708       0       0        708    ?    0   Jun  1
C:\WINNT\system32\mmc.exe
     2324       0       0       2324    ?    0   Jun  1
C:\WINNT\system32\mmc.exe
     1384       1    1384       1384    ?   18   Jun 17
/usr/bin/cygrunsrv
     2796    1384    2796       2496    ?   18   Jun 17 /usr/sbin/sshd
     2792       0       0       2792    ?    0   Jun 17
C:\WINNT\system32\ssstars.scr
     2752    2796    2752       2744    ?   18 12:04:19 /usr/sbin/sshd
     2508    2752    2508       2928    0  500 12:04:26 /usr/bin/bash
     2932       1    2932       2932    ?  500 12:08:36 /usr/sbin/cron
     2604    2508    2604       2844    0  500 17:02:36 /usr/bin/ps
------------------------------------------------------------------------
--------------------------------------------------------------------

I note that the UID for the cron process is 500, the same as the one
for the bash shell I'm running.  UID 500 appears to be able to read
all the files it needs to read in order to do the backup, as when I
run this command from the Administrator command prompt:

[EMAIL PROTECTED] ~
$ /usr/bin/tar czv --exclude-from=/home/Administrator/filelist.txt
--file /home/Administrator/backup.tgz /cygdrive/c/Data/Jobshop

a file of approximately 337Mbytes is created (which is expected) and
it tests fine.

However when I run the same command from a crontab entry (with or
without the redirection of stderr to the file 'backup.out')

48 16 * * * /usr/bin/tar czv
--exclude-from=/home/Administrator/filelist.txt --file
/home/Administrator/backup.tgz /cygdrive/c/Data/Jobshop
2>/home/Administrator/backup.out

I get a file of approximately 1.2 Mbytes (which is not expected) and
it fails testing:

------------------------------------------------------------------------
--------------------------------------------------------------------
[EMAIL PROTECTED] ~
$ tar tzv --file backup.tgz
dr-xr-xr-x Administrators/Domain Users 0 2006-06-01 14:47:53
cygdrive/c/Data/Jobshop/
-rwxrwxrwx MJ/Domain Users         14706 1998-10-13 08:19:54
cygdrive/c/Data/Jobshop/ACT_STD.ENG
-rwxrwxrwx Administrators/Domain Users 693 1997-11-20 13:05:04
cygdrive/c/Data/Jobshop/BTI.CFG
-rwxrwxrwx Administrators/Domain Users 36077 1994-06-25 12:47:30
cygdrive/c/Data/Jobshop/BTIUTILD.MSG
-rwxrwxrwx Administrators/Domain Users 264497 1994-10-27 13:40:32
cygdrive/c/Data/Jobshop/BTRIEVE.EXE
-rwxrwxrwx Administrators/Domain Users    372 1999-05-11 16:35:26
cygdrive/c/Data/Jobshop/BTRON.BAT
-rwxrwxrwx Administrators/Domain Users   5690 1994-09-08 09:56:36
cygdrive/c/Data/Jobshop/BTSTOP.EXE
-rwxrwxrwx Administrators/Domain Users  30939 1994-09-08 09:56:36
cygdrive/c/Data/Jobshop/BTUTIL.EXE
-rwxrwxrwx Administrators/Domain Users  92812 1994-06-27 14:59:32
cygdrive/c/Data/Jobshop/BUTIL.EXE
-rwxrwxrwx Administrators/Domain Users   4357 1994-06-27 14:56:46
cygdrive/c/Data/Jobshop/BUTILDOS.MSG
-rwxrwxrwx Administrators/Domain Users 8726528 2000-12-22 14:05:34
cygdrive/c/Data/Jobshop/CCCTL.DAT
-rwxrwxrwx Administrators/Domain Users  307200 1997-03-25 04:02:00
cygdrive/c/Data/Jobshop/cg32.dll
-rwxrwxrwx Administrators/Domain Users    4937 2000-12-04 15:14:36
cygdrive/c/Data/Jobshop/Clr_840.dem
-rwxrwxrwx Administrators/Domain Users    4937 1999-09-10 15:18:02
cygdrive/c/Data/Jobshop/CLR_840.ENG
-rwxrwxrwx Administrators/Domain Users    5001 1997-06-02 11:58:00
cygdrive/c/Data/Jobshop/CLR_QMS.ENG
-rwxrwxrwx Administrators/Domain Users    5550 1998-08-03 16:18:46
cygdrive/c/Data/Jobshop/CLR_STD.ENG
-rwxrwxrwx Administrators/Domain Users    5000 1998-08-27 13:05:12
cygdrive/c/Data/Jobshop/Colours.eng
-rwxrwxrwx Administrators/Domain Users   81104 1996-11-20 23:00:00
cygdrive/c/Data/Jobshop/COMDLG16.OCX
-rwxrwxrwx Administrators/Domain Users  129808 1997-07-19 16:00:32
cygdrive/c/Data/Jobshop/COMDLG32.OCX
-rwxrwxrwx Administrators/Domain Users    1191 1999-06-01 11:31:08
cygdrive/c/Data/Jobshop/COPYLIVE.BAT
-rwxrwxrwx Administrators/Domain Users   27136 1995-08-13 23:59:58
cygdrive/c/Data/Jobshop/CTL3D32.DLL
-rwxrwxrwx Administrators/Domain Users     108 1998-06-17 13:08:44
cygdrive/c/Data/Jobshop/CURRENCY.ENG
-rwxrwxrwx Administrators/Domain Users      63 2001-05-16 11:38:32
cygdrive/c/Data/Jobshop/Cuscom.bat
-rwxrwxrwx Administrators/Domain Users    2486 2000-09-08 15:30:54
cygdrive/c/Data/Jobshop/cuscom.ini
-rwxrwxrwx Administrators/Domain Users   47104 1996-05-08 04:59:30
cygdrive/c/Data/Jobshop/D2HTLS32.DLL
tar: Unexpected EOF in archive
tar: Error is not recoverable: exiting now
------------------------------------------------------------------------
---------------------------------

The output from the tar job run by cron and written to the file
backup.out looks quite normal:

------------------------------------------------------------------------
---------------------------------
[EMAIL PROTECTED] ~
$ cat backup.out
/usr/bin/tar: Removing leading `/' from member names
------------------------------------------------------------------------
---------------------------------

Sorry if these long lines wrap for you.

73,
Ged.

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

Reply via email to