Hi all, I am experiencing a rather strang problem with cron. I am using cron to make various backups of my system It uses a script that i made. One of the backups is of my home directory, to prevent it from growing too large i make an "ignore"file. In that file are all the directories, so the backups is only of the files in my homedirectory. This is the line of the script that causes the problem when run by cron: ls -l |grep drwx | cut -d':' -f2|cut -d' ' -f2 > skripts/tmp_test To test this i put this line in a seperate script: ~/skripts/test_file tregter4@komkommer:~> cat skripts/test_file ls -l |grep drwx | cut -d':' -f2|cut -d' ' -f2 > skripts/tmp_test When i run it from the commandline: tregter4@komkommer:~> sh ~/skripts/test_file It runs without faults, and puts all my directories in ~/skripts/test_file However, when cron runs the script: 20 22 * * * sh ~/skripts/test_file It makes the same file, but a lot of directories are missing. So my question is, what am i doing wrong, or what causes cron to miss some of my directories. Tnx in advance. Greetings, Cor van Haastregt -- Disc lamer: The mailinglist that you are reading is not the intended recipient of this posting. This is only a test of the echelon and data retention systems. Please archive this message indefinately to allow verification of the logfiles. By reading this message you agree to have your privacy invaded
On Thursday 16 March 2006 23:22, Cor van Haastregt wrote:
However, when cron runs the script: 20 22 * * * sh ~/skripts/test_file It makes the same file, but a lot of directories are missing.
Could you give an example of the directories that are missing and that are included?
So my question is, what am i doing wrong, or what causes cron to miss some of my directories.
I don't see anything immediately that leaps out as being wrong, but with a couple of examples something might ring a bell -- Certified: Yes. Certifiable: of course! jabber ID: anders@rydsbo.net
On Thursday 16 March 2006 23:22, Cor van Haastregt wrote:
ls -l |grep drwx | cut -d':' -f2|cut -d' ' -f2 > skripts/tmp_test
By the way, what is your locale? In the default locale (C or POSIX) not all directory time stamps will have a : in them. The older ones will have a year where newer ones have a clock time I notice the locale nl_NL doesn't do this cron uses the C locale by default You might want to try putting LANG="nl_NL" (or whatever you use) before the ls -l in the script -- Certified: Yes. Certifiable: of course! jabber ID: anders@rydsbo.net
On Thu, Mar 16, 2006 at 11:39:40PM +0100, Anders Johansson wrote:
ls -l |grep drwx | cut -d':' -f2|cut -d' ' -f2 > skripts/tmp_test
By the way, what is your locale? In the default locale (C or POSIX) not all directory time stamps will have a : in them. The older ones will have a year where newer ones have a clock time
I don't know what you mean with this, how can i see the settings of my locale? I am using SuSE 9.3, all updates installed.
I notice the locale nl_NL doesn't do this
cron uses the C locale by default
Can you help me explaining this, an url would be sufficient.
You might want to try putting LANG="nl_NL" (or whatever you use) before the ls -l in the script
Ok, i added LANG="en_US.UTF-8" in front of the ls -l (because that is the output of echo $LANG). Now it works fine. Thanks a lot. The strange thing is, it worked fine untill a month or 3 ago. Anyway, tnx a lot for your help. Grtz, Cor van Haastregt -- Disc lamer: The mailinglist that you are reading is not the intended recipient of this posting. This is only a test of the echelon and data retention systems. Please archive this message indefinately to allow verification of the logfiles. By reading this message you agree to have your privacy invaded
On Friday 17 March 2006 00:21, Cor van Haastregt wrote:
On Thu, Mar 16, 2006 at 11:39:40PM +0100, Anders Johansson wrote:
ls -l |grep drwx | cut -d':' -f2|cut -d' ' -f2 > skripts/tmp_test
By the way, what is your locale? In the default locale (C or POSIX) not all directory time stamps will have a : in them. The older ones will have a year where newer ones have a clock time
I don't know what you mean with this, how can i see the settings of my locale?
The simplest would be to just open a shell and type locale
I am using SuSE 9.3, all updates installed.
I notice the locale nl_NL doesn't do this
cron uses the C locale by default
Can you help me explaining this, an url would be sufficient.
The locale defines all the localisation aspects of your system, which language your error messages will be in, which sort order your system uses, which way your dates are printed etc. etc. etc. Normally your locale is defined by the language you select when you install the system, so if you select English(US) you will get en_US as you did. The C (or POSIX) locale is defined by the posix standard and must be present on any posix compliant system, such as linux. Your command uses the fact that when you do ls -l, the clock in the time stamp will be the first is the on the line that contains a :, but the problem is that in the C locale, the dates aren't printed in the same way as in the en_US locale. If you open a shell and type LANG=C ls -l you'll see what I mean. The older directories (which will probably be the ones which were missing in your file after cron ran the script) will say something like Jan 5 2004 and the other ones will say something like Mar 3 20:03 because the C locale will switch to printing the year once the file/directory becomes old enough. This was what broke your script. cron doesn't use the system locale, so if you rely on it in a script run by cron, you need to set it explicitly
The strange thing is, it worked fine untill a month or 3 ago.
Could it perhaps be that up until that time, the directories weren't old enough? -- Certified: Yes. Certifiable: of course! jabber ID: anders@rydsbo.net
[snip ls -l vs cron question]
cron uses the C locale by default
Can you help me explaining this, an url would be sufficient.
[snip explanation]
LANG=C ls -l
you'll see what I mean. The older directories (which will probably be the ones which were missing in your file after cron ran the script) will say something like
Ahhhhhhhhhh I see. Great. Tnx a lot. tregter4@komkommer:~> LANG=C ls -l drwxr-xr-x 4 tregter4 users 4096 Mar 17 00:45 skripts drwxr-xr-x 2 tregter4 users 4096 Nov 9 23:42 t3 drwxr-xr-x 5 tregter4 users 4096 Jul 28 2005 oldpix vs tregter4@komkommer:~> ls -l drwxr-xr-x 4 tregter4 users 4096 2006-03-17 00:45 skripts drwxr-xr-x 2 tregter4 users 4096 2005-11-09 23:42 t3 drwxr-xr-x 5 tregter4 users 4096 2005-07-28 18:44 oldpix
because the C locale will switch to printing the year once the file/directory becomes old enough. This was what broke your script.
I see now.
cron doesn't use the system locale, so if you rely on it in a script run by cron, you need to set it explicitly
The strange thing is, it worked fine untill a month or 3 ago.
Could it perhaps be that up until that time, the directories weren't old enough?
You are correct. Again tnx a lot. Tnx for the explanation. Grtz, Cor van Haastregt -- Disc lamer: The mailinglist that you are reading is not the intended recipient of this posting. This is only a test of the echelon and data retention systems. Please archive this message indefinately to allow verification of the logfiles. By reading this message you agree to have your privacy invaded
Cor van Haastregt wrote: ...
To test this i put this line in a seperate script: ~/skripts/test_file tregter4@komkommer:~> cat skripts/test_file ls -l |grep drwx | cut -d':' -f2|cut -d' ' -f2 > skripts/tmp_test
Hallo Cor, what about using "find": find . -maxdepth 1 -type d -name "[^.]*" -printf "%f\n" -- Viele Grüße ------------------------------------------------------------------------ Michael
On Fri, Mar 17, 2006 at 08:13:17AM +0100, Michael Behrens wrote:
Cor van Haastregt wrote: ...
To test this i put this line in a seperate script: ~/skripts/test_file tregter4@komkommer:~> cat skripts/test_file ls -l |grep drwx | cut -d':' -f2|cut -d' ' -f2 > skripts/tmp_test
Hallo Cor,
what about using "find":
find . -maxdepth 1 -type d -name "[^.]*" -printf "%f\n"
Great, this also works. Tnx a lot. Grtz, Cor van Haastregt -- Disc lamer: The mailinglist that you are reading is not the intended recipient of this posting. This is only a test of the echelon and data retention systems. Please archive this message indefinately to allow verification of the logfiles. By reading this message you agree to have your privacy invaded
participants (3)
-
Anders Johansson
-
Cor van Haastregt
-
Michael Behrens