Go Down

Topic: Problem programming cron tasks in YUN (Read 11313 times) previous topic - next topic

Roque Campos

Dear Friends,

I don't understand what I'm doing wrong. I have two scripts, wich I want to run. One of them at startup, and one of them once per day. I writed the following in scheduled tasks  using the luci console:

Code: [Select]
@reboot root /mnt/sd/rhc/start.sh  2>&1 >> /mnt/sd/rhc/rhc.log
12 35 * * * root /mnt/sd/rhc/maintenance.sh  2>&1 >> /mnt/sd/rhc/rhc.log


It does not work, and the only error messages that I can see are in the system log:

Code: [Select]
Nov 21 12:37:01 Arduino cron.err crond[1523]: user root: parse error at @reboot
Nov 21 12:37:01 Arduino cron.err crond[1523]: user root: parse error at root
Nov 21 12:37:01 Arduino cron.err crond[1523]: user root: parse error at /mnt/sd/rhc/start.sh
Nov 21 12:37:01 Arduino cron.err crond[1523]: user root: parse error at 2>&1
Nov 21 12:37:01 Arduino cron.err crond[1523]: user root: parse error at >>
Nov 21 12:37:01 Arduino cron.err crond[1523]: user root: parse error at 37


What I'm doing wrong?

Thanks in advance.

lucad79

Hi

probably the cron daemon included in the Linino distribution does not support the @reboot macro...
Morover, the correct cron syntax is

minute hour day month day-of-week

so 12 35 is wrong if you meant to schedule that task at 12:35, the correct entry should be

35 12 * * *
www.lucadentella.it

Roque Campos

Yes, you are right, it seems that the reboot macro is not supported.

In addition to the minute - hour error, there was another error: the user is not needed. The right command that works is:

35 12 * * * /mnt/sd/rhc/maintenance.sh  > /mnt/sd/rhc/rhc.log

Thank you very much for your help

lucad79

you're right, I didn't notice the "root" in front of your command!
www.lucadentella.it

mamu

Have you tried to enable cron first?
According to superuser.com one has to for OpenWrt:

By default OpenWrt does not enable the cron service. To start it and enable automatic startup during subsequent reboots, you need to execute the following commands:

/etc/init.d/cron start
/etc/init.d/cron enable

lucad79

mamu,

the crond used in Linino does not support the tag "@reboot"
bye
www.lucadentella.it

mamu


OttoF

May be the startup initscripts are a possible way to do this
you found it in
LuCi Startup

----------------------------------------------------------------------
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.


wifi-live-or-reset
exit 0
------------------------------------------------------------------------

mamu

OttoF, had a look right now and it looks promising. I will try this.

BTW: Looks like an official hit spot for doing Linino init stuff. Would be nice to find some sort of documentation if this is the right place.

federicofissore

I'm not sure it's the correct way to call it, but OpenWRT (as well as many linux distros) is "init" based, meaning it starts services (so called "daemons") with "init scripts"

That gives you two correct ways to do something at boot time. Modify /etc/rc.local adding your scripts (easiest and quickest way) or adding an init script. Init scripts are usefull only if you need something to run BEFORE something else. That's the case for SSL and GPG key regenaration, for example.

I suggest rc.local: it's easy and it's the LAST thing to run when your yun starts up

mamu

Yep, added the following line to rc.local using LuCI and it works like a charm!
Code: [Select]
(sleep 10;python /www/sd/fg100_yun/server.py)&

Roque Campos

Is there an easy way to redirect the cron logs to another file and not use the system log file?

I tried modifing the cron start scritp in  /etc/init.d/cron, replacing the line

ln -s /etc/crontabs /var/spool/cron/ 2>/dev/null

with

ln -s /etc/crontabs /var/spool/cron/ 2>/another/path

But the cron is still logged to the system log file.

Thaks

mamu

Have you cross-checked with what is displayed in LuCI "System : Scheduled Tasks"?

lucad79

2> is actually redirecting only the STDERR (standard error) stream, not the STDOUT.
Are you trying to redirect the output of the commands you put in the crontab or the log of the cron daemon?
www.lucadentella.it

Roque Campos

#14
Dec 01, 2013, 02:28 pm Last Edit: Dec 01, 2013, 04:55 pm by Roque Campos Reason: 1
My intention was to redirect the ouput of the daemon to a log script in another location but I can live without it. Instead, I redirected the output of the scripts that are called by the cron. It is more or less the same thing.

But I have a curiosity. I have a cron job every minute. Then, every minute a string like that

Code: [Select]
Dec  1 16:58:01 Arduino cron.info crond[30828]: crond: USER root pid 4605 cmd /mnt/sd/rhc/historical_1m.sh


is wroted in the system log. Maybe I'm confused, but, it is dangerous to abuse of the log scripts in the linino memory? I mean, I have read that it is not recommended to use the internal storage of the Linino because of the limited number of writes...

Can this be a problem?

Go Up