cron at specified time

All about firmwares for routers. Support for RouterTech firmwares is here too.
User avatar
cicala
Regular
Regular
Posts: 47
Joined: Sun Nov 26, 2006 2:08 pm

cron at specified time

Post by cicala » Sun May 06, 2007 7:41 am

hi,
is there a way to run a cron job at a specified hour of the day (not at a set interval)?
tnx
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4779
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Re: cron at specified time

Post by Shotokan101 » Sun May 06, 2007 11:25 am

cicala wrote:hi,
is there a way to run a cron job at a specified hour of the day (not at a set interval)?
tnx
Yes - See crontab info - if it's a "runonce" type you require use the at command which is documented at the same link.

EDIT: although the RT F/W only seems to have crontab available if it's to schedule a task on an RT F/W supported router.
Jim

.....I'm Sorry But I Can't Do That Dave.....
User avatar
cicala
Regular
Regular
Posts: 47
Joined: Sun Nov 26, 2006 2:08 pm

Post by cicala » Sun May 06, 2007 3:32 pm

tnx for the answer...

i tried and it work: I'm trying to have the wlan go down and up at scheduled times so i entered in /var/spool/cron/crontabs/root

Code: Select all

0 8 * * * echo "begin;ap:settings/ap_enabled=1;end;begin;ap:status/cli_reboot;logic:command/save;end" | cm_cli_tty
30 23 * * * echo "begin;ap:settings/ap_enabled=0;end;begin;ap:status/cli_reboot;logic:command/save;end" | cm_cli_tty
now i would like to make the changes permanent so i tried using setenv autoexec.sh this way:

Code: Select all

setenv autoexec.sh "echo \"0 8 \* \* \* echo \\\"begin;ap:settings/ap_enabled=1;end;begin;ap:status/cli_reboot;logic:command/save;end\\\" | cm_cli_tty\">>/var/spool/cron/crontabs/root"
but when i type getenv i only see part of the string?? is there a limit of characters that can be typed in the envs??
also tried writing directly to /proc/sys/dev/adam2/environment but with the same resoult :(
any ideas?
tnx
User avatar
Shotokan101
RouterTech Team
RouterTech Team
Posts: 4779
Joined: Thu Jan 26, 2006 3:17 pm
Location: Glasgow, Scotland

Post by Shotokan101 » Sun May 06, 2007 3:46 pm

Sorry I'm not sure :? - if it works interactively then i suspect that the problem is with you trying to write to the router's flash - the autoxexc.sh example in the F/W documentation show how to use a script hosted on n external server though which you could try in the meantime I suppose till Biro or Chief can help out..... :?

NOTE: delete "*" in w*get in example below - need to allow posting only on forum for security purposes.....

Code: Select all

Examples:
1. autoexec.sh
e.g.,
setenv autoexec.sh "cd /var && w*get http://fpp.com/bar.sh && chmod a+x ./bar.sh && ./bar.sh"
This will set up the router to fetch a script (bar.sh) from a website, set its executable flag, and then run it, everytime the router boots up.
Jim

.....I'm Sorry But I Can't Do That Dave.....
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Sun May 06, 2007 6:01 pm

The adam2 environment is slightly brain dead and has a tight limit on the length of what you can store in each variable (I think the limit is 64 characters - but I may be wrong). PSPboot allows much longer values in environment variables. Your best bet is to put your command in a script, store the script on a web server, and then use autoexec.sh to download and run the script.
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
User avatar
cicala
Regular
Regular
Posts: 47
Joined: Sun Nov 26, 2006 2:08 pm

Post by cicala » Sun May 06, 2007 6:44 pm

ok, that explains it.. :(

thanx again for the great work :)
jamon
Novice
Novice
Posts: 11
Joined: Sat Mar 03, 2007 1:13 am

Post by jamon » Tue May 08, 2007 1:04 pm

Shotokan101 wrote:

Code: Select all

Examples:
1. autoexec.sh
e.g.,
setenv autoexec.sh "cd /var && w*get http://fpp.com/bar.sh && chmod a+x ./bar.sh && ./bar.sh"
This will set up the router to fetch a script (bar.sh) from a website, set its executable flag, and then run it, everytime the router boots up.
If the FTP server isn't avaliable, what hapens?
Can you improve the script to try to download the "bar.sh" script up to the server is right and after execute it? I presume that the "autoexec.sh" script is executed before the WAN interface is up, right?
jamon
Novice
Novice
Posts: 11
Joined: Sat Mar 03, 2007 1:13 am

Post by jamon » Tue May 08, 2007 1:22 pm

Looking to "/usr/local/bin/autoexec.sh" I suggest to change this:

Code: Select all

# make sure we have a WAN connection before starting
x=0
while [ $x -le 17 ]
do
  x=`expr $x + 1`
  if ping -c 1 google.com > /dev/null; then
        $@
        exit 0
  fi
  sleep 10
done
To do a ping to a environment var, like AUTOEXEC_SERVER_PING, and perhaps set it as default to "google.com" like now. With this change, I can set an internal FTP server and download my startup script from it, without worrying about if it's active or not.

You agree?
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Tue May 08, 2007 11:10 pm

It may be possible - but I am not promising anything.
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
snakessj
Novice
Novice
Posts: 28
Joined: Thu Jan 29, 2009 11:18 pm

HELP!!!

Post by snakessj » Thu Jan 29, 2009 11:29 pm

Hi! I will schedule a job with crontab but, when I modify "/var/spool/cron/crontabs/root" adding a line such
"36 17 * * * wget -q -O /dev/null 'http://www.site.com/page.php'
and attending the time specified, nothing happens! What's wrong? :cry:
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Fri Jan 30, 2009 12:49 am

Is cron enabled? Is sntp enabled? What does "crontab -l" say?
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
snakessj
Novice
Novice
Posts: 28
Joined: Thu Jan 29, 2009 11:18 pm

Post by snakessj » Fri Jan 30, 2009 7:13 pm

Is cron enabled?
I don't know! :( How verify?

Is sntp enabled?
I don't know! :( (What is?) How verify?

What does "crontab -l" say?
0 */1 * * * /usr/local/bin/memopt.sh& >/dev/null 2>&1
0 */1 * * * /usr/local/bin/chksync.sh& >/dev/null 2>&1
0 */2 * * * cat /proc/avalanche/avsar_modem_stats | grep Attenuation | logger
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Fri Jan 30, 2009 7:41 pm

Advanced->sntp
Tools->RT configurations
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
snakessj
Novice
Novice
Posts: 28
Joined: Thu Jan 29, 2009 11:18 pm

Post by snakessj » Fri Jan 30, 2009 9:07 pm

SNTP is active! :D

In don't have "RT configurations" the version of my firmware is "2.30" =\

My Tools menù:
System Commands
Remote Log
User Management
Update Gateway
Ping Test
Log Settings
Gateway System Information
System Diagnostics
Optimise RAM
Run Command
Reboot Router
Shutdown Router
Log Out
User avatar
thechief
RouterTech Team
RouterTech Team
Posts: 12067
Joined: Wed Feb 01, 2006 10:22 pm
Location: England, the Centre of Africa
Contact:

Post by thechief » Fri Jan 30, 2009 10:01 pm

Post the output of "ps aux".
The Chief: :afro: Be sure to read the Firmware FAQ and do a Forum Search before posting!
No support via PM. Ask all questions on the open forum.
Post Reply