LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   crand cannot automaticlly work problem (https://www.linuxquestions.org/questions/linux-general-1/crand-cannot-automaticlly-work-problem-4175441915/)

leon.zcom 12-18-2012 01:29 AM

crand cannot automaticlly work problem
 
In mips enbedded system, i want to do someting periodically, but it cannot work. the code is as follow.

autochannel.sh
/**********************************************/
#!/bin/sh
/sbin/iwconfig ath0 channel 0
/**********************************************/

autochannelschedule
/**********************************************/
*/1 * * * * /bin/sh /etc/autochannel.sh
/**********************************************/

in my main process, the code is
/**********************************************/
systemf("echo \' %s /bin/sh /etc/autochannel.sh \' > /tmp/autochannelschedule"," */1 * * * *");
system("chmod 777 /tmp/autochannelschedule");
system("/usr/bin/crontab -d");
system("/usr/bin/crontab /tmp/autochannelschedule");
system("killall -9 crond && /usr/sbin/crond");
/**********************************************/

after system up, i use "crontab -l", the echo is "*/1 * * * * /bin/sh /etc/autochannel.sh" .

Can someone tell me what's the problem? Thanks.

unSpawn 01-13-2013 11:11 AM

Quote:

Originally Posted by leon.zcom (Post 4851472)
Can someone tell me what's the problem?

No because we don't know the user you execute commands as (who's crontab this is) and we haven't seen cron log (error) entries or emailed output. Depending on your crond version 0) the cron daemon should pick up crontab changes automagically and a static task like yours may be 1) dumped in /etc/cron.d/:
Code:

echo '*/1 * * * * root /sbin/iwconfig ath0 channel 0' > /etc/cron.d/iwsetchan.cron
or 2) loaded from a temporary crontab (as mucking with /var/spool/cron/ files isn't SOP) like you already showed:
Code:

umask 027; /usr/bin/crontab -u root -l|grep -v iwconfig > /tmp/.crontab
echo '*/1 * * * * root /sbin/iwconfig ath0 channel 0' >> /tmp/.crontab
/usr/bin/crontab -u root /tmp/.crontab; rm -f /tmp/.crontab

The difference here is I specify a crontab user instead of assuming it, modify the existing crontab instead of replacing it and don't restart crond because it picks up crontab changes automagically. That leaves the question why on earth you would want to schedule this particular command to run every minute but then again it's your system...


//NTLB

leon.zcom 01-14-2013 12:11 AM

Thanks. I had fixed the problem.

But I didn't know the reason. I just modified the crontab file again and again, then test it.

Then It worked.


All times are GMT -5. The time now is 08:55 PM.