raspberry pi - Another RPi idiot who can't understand cron -


me big dum nooby, no grok cron, pleez fix brain.

from pi home directory, type:

crontab -e 

and @ bottom of file add line:

*/5 * * * * date "+(0 6) %h:%m %z" >> /home/pi/scripts/scripts.log 

according instructions i've read elsewhere while thrashing on web; take mean every 5 minutes system date printed scripts.log. did add blank line after this, saved , exited nano, , got message "crontab: installing new crontab".

i waited, , nothing happened. went raspi-config, set time zone, , rebooted, though shouldn't matter since it's supposed run every 5 minutes, not @ specific time. yes, created scripts directory... after third try... still nothing. no output @ command line, nothing in scripts directory, no error messages.

sorry rehash what's been covered before, threads i've read in context of specific project, , don't know enough yet separate out info i'm looking for. want something, anything, work using cron, i'll think next thing screw up.

my abject gratitude , hollow promise buy beer.

edit: referral thread, i'm confused more. script supposed running? commands have part of file, rather executed directly if they're typed on command line? (i hope makes sense.) lines start env >/tmp/test.sh.dummy supposed in script file date command, or part of crontab file?

edit 2: ok, i've rtfm'ed on web several hours, , understand cron runs scripts. laboring under assumption sort of "batch file," commands would typed @ command line , executed in same way.

let's forget damn "date" thing, want work @ all. i've typed on command line:

echo "this test." 

that worked expected. created shell file, in scripts directory in pi directory, called firstscript.sh. reads follows:

#!/bin/bash echo "this test." 

on command line, typed:

sudo chmod +x /home/pi/scripts/firstscript.sh 

in cron table, i've entered line:

* */2 * * * /home/pi/scripts/firstscript.sh 

...with carriage-return @ end. after commented lines. there no #! (hashbang?) @ beginning of file, did not add one. saved this, got response crontab: installing new crontab.

if understand correctly, should run every 2 minutes. waited 10 minutes. rebooted, waited 10. tried same, command in crontab line changed ./firstscript.sh. bupkus.

forgive long-windedness of this, don't know enough what's going on know details relevant.

me big dum ekspurt, pleez me fix own brain.

i figured out problem is. i've seen before, , should have recognized problem when saw again.

quoting crontab(5) man page:

percent-signs (%) in command, unless escaped backslash (\), changed newline characters, , data after first % sent command standard input.

the % characters in arguments date command being intercepted cron daemon, , changed newlines. creating invalid command. need change this:

*/5 * * * * date "+(0 6) %h:%m %z" >> /home/pi/scripts/scripts.log 

to this:

*/5 * * * * date "+(0 6) \%h:\%m \%z" >> /home/pi/scripts/scripts.log 

and should work.

as mentioned in comments, command in crontab line not need shell script. can command can execute shell prompt, except it's run in restricted environment. in cases, including one, have aware cron process command before passing on /bin/sh executed.

replacing date command shell script same thing have worked (as long script name doesn't include % characters), it's not necessary.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -