public inbox for gentoo-user@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-user] crontab not executing
@ 2011-06-19 22:37 Grant
  2011-06-19 23:45 ` David W Noon
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Grant @ 2011-06-19 22:37 UTC (permalink / raw
  To: Gentoo mailing list

One of my systems has a crontab like this to clean up and consolidate
the output of the video monitoring app "motion":

# crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/home/grant/cron.root.txt installed on Sat Sep 25 10:42:18 2010)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
50 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.jpg
55 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.avi
59 23 * * * /usr/bin/mencoder /home/motion/$(date +%Y%m%d)*.avi -noidx
-o /home/motion/full-$(date +%Y%m%d).avi -ovc copy -oac copy

If I execute each command manually, it works great, but nothing
happens otherwise.  Can someone tell me why this crontab doesn't seem
to be executing?

- Grant



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-19 22:37 [gentoo-user] crontab not executing Grant
@ 2011-06-19 23:45 ` David W Noon
  2011-06-20  5:18 ` Florian Philipp
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 15+ messages in thread
From: David W Noon @ 2011-06-19 23:45 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 2605 bytes --]

On Sun, 19 Jun 2011 15:37:42 -0700, Grant wrote about [gentoo-user]
crontab not executing:

> One of my systems has a crontab like this to clean up and consolidate
> the output of the video monitoring app "motion":
> 
> # crontab -l
> # DO NOT EDIT THIS FILE - edit the master and reinstall.
> # (/home/grant/cron.root.txt installed on Sat Sep 25 10:42:18 2010)
> # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42
> vixie Exp $) 50 23 * * * /bin/rm /home/motion/$(date -d 'yesterday'
> +%Y%m%d)*.jpg 55 23 * * * /bin/rm /home/motion/$(date -d 'yesterday'
> +%Y%m%d)*.avi 59 23 * * * /usr/bin/mencoder /home/motion/$(date
> +%Y%m%d)*.avi -noidx -o /home/motion/full-$(date +%Y%m%d).avi -ovc
> copy -oac copy
> 
> If I execute each command manually, it works great, but nothing
> happens otherwise.  Can someone tell me why this crontab doesn't seem
> to be executing?

For starters, you don't have any environment variables assigned at the
top of your crontab.  Here is mine:

# Establish environment variables.
JAVA_HOME='/etc/java-config-2/current-system-vm'
PATH='/home/dwn/bin:/usr/local/bin:/bin:/usr/bin:/etc/java-config-2/current-system-vm/bin:/etc/java-config-2/current-system-vm/jre/bin:/opt/bin'
TMPDIR='/tmp'
HOME='/home/dwn'
SHELL='/bin/zsh'
LOGNAME='dwn'
LC_ALL='en_GB.UTF-8'
http_proxy='http://localhost:8080'
ftp_proxy='http://localhost:8080'
RSYNC_PROXY='localhost:8080'
ZFTP_PREFS='P'
PGHOST=''
PGPORT=''

# Set our priority level.
!nice(4)

# Clean up old backup files.
%daily 38 20 find "$HOME/" \( -name \*~ -o -iname \*.bak -o -iname \*.bak\? \) -print -delete

# Clean out the work directory for Lazarus.
%daily 18 05 find "$HOME/Lazarus_projects/tmp/" -mindepth 1 -delete

# Download the development trunk of Free Pascal compiler.
%daily 13 07 fpc_download.zsh

# Purge old mailing list messages from Free Pascal.
%daily 37 04 mail_purge.py '6d5c5c5a8aa90d8a'

# Clear the cache for epiphany.
%daily 27 06 cd "$HOME/.gnome2/epiphany/mozilla/epiphany" && rm -rf
compreg.dat pluginreg.dat Cache .parentlock

# Clean out old GNOME sessions.
#%hourly 13 find "$HOME/.config/gnome-session/saved-session/" -mindepth
1 -name \*.desktop -delete

# Clean out the cache subdirectories under $HOME.
%daily 28 06 cache_clean.zsh

# Check Portage for orphans.
#%daily 32 06 portage_orphans.zsh
-- 
Regards,

Dave  [RLU #314465]
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
dwnoon@ntlworld.com (David W Noon)
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-19 22:37 [gentoo-user] crontab not executing Grant
  2011-06-19 23:45 ` David W Noon
@ 2011-06-20  5:18 ` Florian Philipp
  2011-06-20  6:30   ` Adam Carter
  2011-06-20 12:52 ` Todd Goodman
       [not found] ` <1426203.rtguKxDEjI@nazgul>
  3 siblings, 1 reply; 15+ messages in thread
From: Florian Philipp @ 2011-06-20  5:18 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

Am 20.06.2011 00:37, schrieb Grant:
> One of my systems has a crontab like this to clean up and consolidate
> the output of the video monitoring app "motion":
> 
> # crontab -l
> # DO NOT EDIT THIS FILE - edit the master and reinstall.
> # (/home/grant/cron.root.txt installed on Sat Sep 25 10:42:18 2010)
> # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
> 50 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.jpg
> 55 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.avi
> 59 23 * * * /usr/bin/mencoder /home/motion/$(date +%Y%m%d)*.avi -noidx
> -o /home/motion/full-$(date +%Y%m%d).avi -ovc copy -oac copy
> 
> If I execute each command manually, it works great, but nothing
> happens otherwise.  Can someone tell me why this crontab doesn't seem
> to be executing?
> 
> - Grant
> 

I might be wrong but as I understand it, cron executes your commands in
/bin/sh, not /bin/bash. Therefore you should use the `date -d
'yesterday' +%Y%m%d` syntax instead of $(date -d 'yesterday' +%Y%m%d).

Additionally, % signs are replaced with newlines. You have to escape
them: `date -d 'yesterday' +\%Y\%m\%d`

Hope this helps,
Florian Philipp


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20  5:18 ` Florian Philipp
@ 2011-06-20  6:30   ` Adam Carter
  2011-06-20  8:21     ` Neil Bothwick
  0 siblings, 1 reply; 15+ messages in thread
From: Adam Carter @ 2011-06-20  6:30 UTC (permalink / raw
  To: gentoo-user

> I might be wrong but as I understand it, cron executes your commands in
> /bin/sh, not /bin/bash.

/bin/sh is a symlink to bash.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20  6:30   ` Adam Carter
@ 2011-06-20  8:21     ` Neil Bothwick
  2011-06-20  9:07       ` Florian Philipp
  2011-06-20 10:39       ` Adam Carter
  0 siblings, 2 replies; 15+ messages in thread
From: Neil Bothwick @ 2011-06-20  8:21 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 328 bytes --]

On Mon, 20 Jun 2011 16:30:12 +1000, Adam Carter wrote:

> > I might be wrong but as I understand it, cron executes your commands
> > in /bin/sh, not /bin/bash.  
> 
> /bin/sh is a symlink to bash.

Which runs as sh when run from the symlink.


-- 
Neil Bothwick

She's fine, upstanding, and wonderful laying down.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20  8:21     ` Neil Bothwick
@ 2011-06-20  9:07       ` Florian Philipp
  2011-06-20 10:39       ` Adam Carter
  1 sibling, 0 replies; 15+ messages in thread
From: Florian Philipp @ 2011-06-20  9:07 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 677 bytes --]

Am 20.06.2011 10:21, schrieb Neil Bothwick:
> On Mon, 20 Jun 2011 16:30:12 +1000, Adam Carter wrote:
> 
>>> I might be wrong but as I understand it, cron executes your commands
>>> in /bin/sh, not /bin/bash.  
>>
>> /bin/sh is a symlink to bash.
> 
> Which runs as sh when run from the symlink.
> 
> 

Interestingly, the new style of command substitution has been added to
the POSIX standard.
http://pubs.opengroup.org/onlinepubs/009695399/

I always thought bash was just lazy when it accepted that syntax in sh
mode and therefore could fail if you use dash as a sh replacement or
something alike. Well, lifelong learning ...

Regards,
Florian Philipp


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20  8:21     ` Neil Bothwick
  2011-06-20  9:07       ` Florian Philipp
@ 2011-06-20 10:39       ` Adam Carter
  2011-06-20 11:22         ` Albert Hopkins
                           ` (3 more replies)
  1 sibling, 4 replies; 15+ messages in thread
From: Adam Carter @ 2011-06-20 10:39 UTC (permalink / raw
  To: gentoo-user

>> /bin/sh is a symlink to bash.
>
> Which runs as sh when run from the symlink.

I dont understand. "runs as" usually means "runs under the user
context" to me - are you saying bash has an sh compatibility mode?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20 10:39       ` Adam Carter
@ 2011-06-20 11:22         ` Albert Hopkins
  2011-06-20 11:30         ` Neil Bothwick
                           ` (2 subsequent siblings)
  3 siblings, 0 replies; 15+ messages in thread
From: Albert Hopkins @ 2011-06-20 11:22 UTC (permalink / raw
  To: gentoo-user



On Monday, June 20 at 20:39 (+1000), Adam Carter said:

> I dont understand. "runs as" usually means "runs under the user
> context" to me - are you saying bash has an sh compatibility mode?

Yes, when run as sh in POSIX mode (i.e. if it were called as "bash
--posix").





^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20 10:39       ` Adam Carter
  2011-06-20 11:22         ` Albert Hopkins
@ 2011-06-20 11:30         ` Neil Bothwick
  2011-06-20 11:53         ` Florian Philipp
  2011-06-20 13:52         ` Willie Wong
  3 siblings, 0 replies; 15+ messages in thread
From: Neil Bothwick @ 2011-06-20 11:30 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 661 bytes --]

On Mon, 20 Jun 2011 20:39:00 +1000, Adam Carter wrote:

> >> /bin/sh is a symlink to bash.
> >
> > Which runs as sh when run from the symlink.
> 
> I dont understand. "runs as" usually means "runs under the user

That's one possible use of the term, but English rarely has one meaning
per phrase.

> context" to me - are you saying bash has an sh compatibility mode?

Yes.

"If bash  is invoked with the name sh, it tries to mimic the startup
 behavior of historical versions of sh  as closely as possible, while
 conforming to the POSIX standard as well."


-- 
Neil Bothwick

If a turtle doesn't have a shell, is he homeless or naked?

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20 10:39       ` Adam Carter
  2011-06-20 11:22         ` Albert Hopkins
  2011-06-20 11:30         ` Neil Bothwick
@ 2011-06-20 11:53         ` Florian Philipp
  2011-06-20 13:52         ` Willie Wong
  3 siblings, 0 replies; 15+ messages in thread
From: Florian Philipp @ 2011-06-20 11:53 UTC (permalink / raw
  To: gentoo-user

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

Am 20.06.2011 12:39, schrieb Adam Carter:
>>> /bin/sh is a symlink to bash.
>>
>> Which runs as sh when run from the symlink.
> 
> I dont understand. "runs as" usually means "runs under the user
> context" to me - are you saying bash has an sh compatibility mode?
> 

Yes, that's exactly what he wants to say.
Interestingly, that mode still supports most bash-only features like
arrays. I guess they can do this because it doesn't change the semantic
of old Bourne shell code. It just makes some formerly invalid syntax valid.

/bin/sh -c -c 'array=( sh bash ); echo I am a ${array[1]}' 2>/dev/null
|| echo I am a sh
> I am a bash

Other drop-in replacements for /bin/sh like dash are less forgiving:

/bin/dash -c -c 'array=( sh bash ); echo I am a ${array[1]}' 2>/dev/null
|| echo I am a sh
> I am a sh


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-19 22:37 [gentoo-user] crontab not executing Grant
  2011-06-19 23:45 ` David W Noon
  2011-06-20  5:18 ` Florian Philipp
@ 2011-06-20 12:52 ` Todd Goodman
       [not found] ` <1426203.rtguKxDEjI@nazgul>
  3 siblings, 0 replies; 15+ messages in thread
From: Todd Goodman @ 2011-06-20 12:52 UTC (permalink / raw
  To: gentoo-user

* Grant <emailgrant@gmail.com> [110619 18:09]:
> One of my systems has a crontab like this to clean up and consolidate
> the output of the video monitoring app "motion":
> 
> # crontab -l
> # DO NOT EDIT THIS FILE - edit the master and reinstall.
> # (/home/grant/cron.root.txt installed on Sat Sep 25 10:42:18 2010)
> # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
> 50 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.jpg
> 55 23 * * * /bin/rm /home/motion/$(date -d 'yesterday' +%Y%m%d)*.avi
> 59 23 * * * /usr/bin/mencoder /home/motion/$(date +%Y%m%d)*.avi -noidx
> -o /home/motion/full-$(date +%Y%m%d).avi -ovc copy -oac copy
> 
> If I execute each command manually, it works great, but nothing
> happens otherwise.  Can someone tell me why this crontab doesn't seem
> to be executing?
> 
> - Grant

How did you edit and which file did you edit?

Did you use crontab -e?

Todd



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20 10:39       ` Adam Carter
                           ` (2 preceding siblings ...)
  2011-06-20 11:53         ` Florian Philipp
@ 2011-06-20 13:52         ` Willie Wong
  3 siblings, 0 replies; 15+ messages in thread
From: Willie Wong @ 2011-06-20 13:52 UTC (permalink / raw
  To: gentoo-user

On Mon, Jun 20, 2011 at 08:39:00PM +1000, Adam Carter wrote:
> >> /bin/sh is a symlink to bash.
> >
> > Which runs as sh when run from the symlink.
> 
> I dont understand. "runs as" usually means "runs under the user
> context" to me - are you saying bash has an sh compatibility mode?


Yes, from the bash man page:

       If  bash  is  invoked  with  the name sh, it tries to mimic the startup
       behavior of historical versions of sh as  closely  as possible,  while
       conforming  to the POSIX standard as well.  When invoked as an interac‐
       tive login shell, or a non-interactive shell with the  --login option,
       it  first  attempts  to read and execute commands from /etc/profile and
       ~/.profile, in that order.  The  --noprofile  option  may  be used  to
       inhibit  this  behavior.  When invoked as an interactive shell with the
       name sh, bash looks for the variable ENV, expands its value  if it  is
       defined,  and uses the expanded value as the name of a file to read and
       execute.  Since a shell invoked as sh does not attempt to read and exe‐
       cute  commands from any other startup files, the --rcfile option has no
       effect.  A non-interactive shell invoked with  the  name  sh  does  not
       attempt  to  read  any  other  startup files.  When invoked as sh, bash
       enters posix mode after the startup files are read.

W
-- 
Willie W. Wong                                     wwong@math.princeton.edu
Data aequatione quotcunque fluentes quantitae involvente fluxiones invenire 
         et vice versa   ~~~  I. Newton



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
       [not found] ` <1426203.rtguKxDEjI@nazgul>
@ 2011-06-20 14:47   ` Grant
  2011-06-20 14:57     ` Peter Humphrey
  0 siblings, 1 reply; 15+ messages in thread
From: Grant @ 2011-06-20 14:47 UTC (permalink / raw
  To: Gentoo mailing list

>> One of my systems has a crontab like this to clean up and
>> consolidate the output of the video monitoring app "motion":
>>
>> # crontab -l
>> # DO NOT EDIT THIS FILE - edit the master and reinstall.
>> # (/home/grant/cron.root.txt installed on Sat Sep 25 10:42:18 2010)
>> # (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42
>> vixie Exp $) 50 23 * * * /bin/rm /home/motion/$(date -d 'yesterday'
>> +%Y%m%d)*.jpg 55 23 * * * /bin/rm /home/motion/$(date -d
>> 'yesterday' +%Y%m%d)*.avi 59 23 * * * /usr/bin/mencoder
>> /home/motion/$(date +%Y%m%d)*.avi -noidx -o
>> /home/motion/full-$(date +%Y%m%d).avi -ovc copy -oac copy
>>
>> If I execute each command manually, it works great, but nothing
>> happens otherwise.  Can someone tell me why this crontab doesn't
>> seem to be executing?
>
> crontab does not use the same shell you use, so when your crons run
> they are missing all of the niceties you are used to using yourself.
>
> Things like PATH for example, and the $() may or may not work.
>
> You have paths for rm and mencoder but not for date

I've switched to this but I can't find the date binary.  Does anyone
know the full path for date?

50 23 * * * /bin/rm /home/motion/`date -d 'yesterday' +\%Y\%m\%d`*.jpg
55 23 * * * /bin/rm /home/motion/`date -d 'yesterday' +\%Y\%m\%d`*.avi
59 23 * * * /usr/bin/mencoder /home/motion/`date +\%Y\%m\%d`*.avi
-noidx -o /home/motion/full-`date +\%Y\%m\%d`.avi -ovc copy -oac copy

- Grant



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20 14:47   ` Grant
@ 2011-06-20 14:57     ` Peter Humphrey
  2011-06-22 14:40       ` Grant
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Humphrey @ 2011-06-20 14:57 UTC (permalink / raw
  To: gentoo-user

On Monday 20 June 2011 15:47:50 Grant wrote:

> I've switched to this but I can't find the date binary.  Does anyone
> know the full path for date?

$ which date
/bin/date

$ qfile date
sys-apps/coreutils (/bin/date)

-- 
Rgds
Peter



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [gentoo-user] crontab not executing
  2011-06-20 14:57     ` Peter Humphrey
@ 2011-06-22 14:40       ` Grant
  0 siblings, 0 replies; 15+ messages in thread
From: Grant @ 2011-06-22 14:40 UTC (permalink / raw
  To: gentoo-user

>> I've switched to this but I can't find the date binary.  Does anyone
>> know the full path for date?
>
> $ which date
> /bin/date
>
> $ qfile date
> sys-apps/coreutils (/bin/date)

Thank you everyone.  I think it's working now.

- Grant



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2011-06-22 14:42 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-19 22:37 [gentoo-user] crontab not executing Grant
2011-06-19 23:45 ` David W Noon
2011-06-20  5:18 ` Florian Philipp
2011-06-20  6:30   ` Adam Carter
2011-06-20  8:21     ` Neil Bothwick
2011-06-20  9:07       ` Florian Philipp
2011-06-20 10:39       ` Adam Carter
2011-06-20 11:22         ` Albert Hopkins
2011-06-20 11:30         ` Neil Bothwick
2011-06-20 11:53         ` Florian Philipp
2011-06-20 13:52         ` Willie Wong
2011-06-20 12:52 ` Todd Goodman
     [not found] ` <1426203.rtguKxDEjI@nazgul>
2011-06-20 14:47   ` Grant
2011-06-20 14:57     ` Peter Humphrey
2011-06-22 14:40       ` Grant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox