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:
@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:
Nov 21 12:37:01 Arduino cron.err crond: user root: parse error at @reboot
Nov 21 12:37:01 Arduino cron.err crond: user root: parse error at root
Nov 21 12:37:01 Arduino cron.err crond: user root: parse error at /mnt/sd/rhc/start.sh
Nov 21 12:37:01 Arduino cron.err crond: user root: parse error at 2>&1
Nov 21 12:37:01 Arduino cron.err crond: user root: parse error at >>
Nov 21 12:37:01 Arduino cron.err crond: user root: parse error at 37
What I'm doing wrong?
Thanks in advance.
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 * * *
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
you're right, I didn't notice the "root" in front of your command!
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:
the crond used in Linino does not support the tag "@reboot"
Ok, that is.... Sad
May be the startup initscripts are a possible way to do this
you found it in
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
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.
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
Yep, added the following line to rc.local using LuCI and it works like a charm!
(sleep 10;python /www/sd/fg100_yun/server.py)&
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
ln -s /etc/crontabs /var/spool/cron/ 2>/another/path
But the cron is still logged to the system log file.
Have you cross-checked with what is displayed in LuCI "System : Scheduled Tasks"?
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?
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
Dec 1 16:58:01 Arduino cron.info crond: 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?
I have always tried to avoid writing any logs, lock files, etc... on the 'default' location which is typically somewhere in the Linino's memory. I tried to put all those files on the SD-card, just for the reason you mentioned. It would be nice to get confirmation that this indeed the best thing to do to avoid writes on the Linino internal memory.. (note that I am not (yet) using cron)
I agree with you and I think that this can be a problem. But per default the from output is logged to syslog and I don't, know how change it.
Maybe the solution is to reduce the level of the messages that are logged to the syslog, I don't, know how to do this also.
It would be nice to get confirmation that this indeed the best thing to do to avoid writes on the Linino internal memory.. (note that I am not (yet) using cron)
The less you use the flash, the longer the yun will last. Flash memory has a limited number of writes (I don't know the exact number though: some say 10.000) just as your sd card BUT
1) if the flash of the yun wears out, the yun is gone
2) sd cards are so much bigger and therefore have so many blocks that it's hard to write 10.000 times on each of them
Yes, I understand you very well. But what I want to explain is that the string that are logged to files like syslog, are logged by default. I mean, it is not my decision: I program a cronjob every minute, and every minute the syslog is writed.
Maybe this behaviour may be disabled by default... or at least, I need to know how to change it.
Hope you understand my not very good English. :~
I think this is an important issue with regards to the lifetime of a Yun.
If the default location where e.g. cron drops its log-file can not be changed, an alternative might be to lock directories for writing?
I was searching through the internet, and I found the following page:
and the following paragraph:
Syslogd writes the log messages it receives into a file or into the RAM ringbuffer (option -C). The file is a file, it can be accessed with cat, less, vi, etc. The data in the RAM ringbuffer should be accessed with logread. You can of course use pipes, like logread -f | nc 192.168.1.1 514 or logread -f » /mnt/share/logfile (reasonable on non-flash media, see usb.storage or nfs.client) or pretty much whatever you want.
Then I did a little test with my arduino, turning it off and on, and it is true, all the messages of the syslog are gone. I suppose that this means that the syslog file is not written to the flash memory. It seems that the syslog file is writtent to the ram ringbuffer.
In this case, I understand that there is not a problem having cron jobs wich outputs data to the syslog, because the flash memory is not used.
Am I right?
Thanks in advance.
i hope so, because i have a cronjob every minute :smiley-eek-blue:
yes don't worry... to be sure run
ps | grep syslogd
and you'll find it runs with the -C option...