Scheduler


joksi

Networkin' Nut
Member
Hi all,

I have a small issue. I have script when run on the command line everything works as expected, however when I run it through the Tomato scheduler (and send the ouput to a new file) It doesn't work. My question is, does the scheduler run commands differently then on the command line, like another user, other environment variables and so on?
 
The scheduler should run commands the same as the command line. I just tried the following and was able to send the output to a new file. It looks like the scheduler is run as root and it looks like the scheduler runs in the /tmp/home/root dir. So maybe look in there for your output if you didn't specify the output file location.

test.sh file ran in scheduler
Code:
#!/bin/sh
echo "foo" > /cifs1/outfoo
echo $(env) # See what environment variables the scheduler has

Code:
cru a test "* * * * * /cifs1/test.sh > /cifs1/output"

foo was seen in /cifs1/outfoo file and the content below is whats in the output file
Code:
USER=root
SHLVL=2
HOME=/root
LOGNAME=root
TERM=vt100
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/sbin:/opt/bin
SHELL=/bin/sh
PWD=/tmp/home/root
 
Hi all,

I have a small issue. I have script when run on the command line everything works as expected, however when I run it through the Tomato scheduler (and send the ouput to a new file) It doesn't work. My question is, does the scheduler run commands differently then on the command line, like another user, other environment variables and so on?

If your script works via CLi but it doesn't via scheduler, the reason is simple, "scheduler" (i.e. cron) doesn't know the time when it has to run your script. :p

Check if there is no problem with Tomato time in "Basic" "Time", receiving KoD packets from an NTP Server can happen quite often if you use an internal NTP Server for instance.
 
Hmm, it does run the script at correct time, however something happens in the middle. The file logging the output shows that it start, but not more...
 
The scheduler should run commands the same as the command line. I just tried the following and was able to send the output to a new file. It looks like the scheduler is run as root and it looks like the scheduler runs in the /tmp/home/root dir. So maybe look in there for your output if you didn't specify the output file location.

test.sh file ran in scheduler
Code:
#!/bin/sh
echo "foo" > /cifs1/outfoo
echo $(env) # See what environment variables the scheduler has

Code:
cru a test "* * * * * /cifs1/test.sh > /cifs1/output"

foo was seen in /cifs1/outfoo file and the content below is whats in the output file
Code:
USER=root
SHLVL=2
HOME=/root
LOGNAME=root
TERM=vt100
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/sbin:/opt/bin
SHELL=/bin/sh
PWD=/tmp/home/root

Yes, other scripts seem to run, but in this case it doesn't. It's a bash script and it seem to start it, cause it logs the first line of output from the script, but then seem to halt because I can verify that the expected end result of the script isnt happening...
 
Yes, other scripts seem to run, but in this case it doesn't. It's a bash script and it seem to start it, cause it logs the first line of output from the script, but then seem to halt because I can verify that the expected end result of the script isnt happening...
Post the code of your script, otherwise it's just guessing games.
 
Post the code of your script, otherwise it's just guessing games.

Of course! Actually, it's not my own script as such, it's a Bash-script called "dehydrated" managing the Let's Encrypt free SSL-certificate. I have tried running it directly from the scheduler, and also wrapping it up in another shell script (that cd's into the directory, and runs the actual script). Both methods are giving me issues.

According to the community over att Dehydrates github-page it *should* work in a standard crontab...

https://github.com/lukas2511/dehydrated/blob/master/dehydrated
 
Of course! Actually, it's not my own script as such, it's a Bash-script called "dehydrated" managing the Let's Encrypt free SSL-certificate. I have tried running it directly from the scheduler, and also wrapping it up in another shell script (that cd's into the directory, and runs the actual script). Both methods are giving me issues.

According to the community over att Dehydrates github-page it *should* work in a standard crontab...

https://github.com/lukas2511/dehydrated/blob/master/dehydrated
You stated it makes it through some of it, as there's a line of output from the script. What line is it specifically? It may serve as a marker to start from in the code.
 
The line is "# INFO: Using main config file /jffs/LetsEncrypt/config"

According to the following guide it should work, however they seem to be using Cron-version from Entware.

https://github.com/Entware-ng/Entware-ng/wiki/Using-Let's-Encrypt

opkg install cron

Create cron job by placing following script to /opt/etc/cron.monthly/renew_certs.sh:

#!/bin/sh
cd /opt/etc/nginx
bash ./dehydrated --domain my.domain.ru --cron
nginx -s reload

and make it executable:

chmod +x /opt/etc/cron.monthly/renew_certs.sh

Don't forget to start cron:

/opt/etc/init.d/S10cron start
 
It looks like it was a $PATH issue, added the same $PATH to the wrapper shell script as when logged in to the shell, and now it runs as expected!
 

Back
Top