Jump to content

Please help with go-script and cron


Recommended Posts

Hello everybody.

 

I have a dyndns script located at /boot/dyndns.sh

I would like to automatically run  this script every hour.

 

I have read a lot of threads and the wiki entry, but I don't really understand the combination of go-script and cron.

I know of have to write something into the go-script that will invoke cron to run, but I don't know what to write exactly.

 

Thanks and help me learn please :D

Link to comment

Add this line to your /boot/config/go script:

echo "25 * * * * /boot/dyndns.sh" >> /var/spool/cron/crontabs/root

 

When the go script is run at startup, this line will be added to cron:

25 * * * * /boot/dyndns.sh

 

Which will run the script at /boot/dyndns.sh every hour 25 minutes after the hour. If you prefer to run the script at a different time hourly (such as 1 minute after the hour, change the 25 to 1).

Link to comment

If you end up needing to add several lines (multiple scripts) to cron, you can create a file containing all the commands (I created /boot/custom/mycron). Then instead of using echo, I cat the file to cron like this:

cat /boot/custom/mycron >> /var/spool/cron/crontabs/root

 

Make sure that you are using 2 greater than symbols ">>", which will append your additions to cron while leaving existing commands in cron. If you use a single greater than symbol ">", you will overwrite the contents of cron.

 

If you would like to know a little more about cron, http://en.wikipedia.org/wiki/Cron has some good information. If you still have questions, let me know.

Link to comment

That is an old post from 2010 & it appears that it was for unRAID 4.x (since the edit mentions 5.x versions to do something different). The method I suggested is working on my unRAID server & I have no errors. I've used this in several unRAID 5.x versions.

 

The method listed in the thread you linked seems to be a much longer way of accomplishing the same task. It copies out the existing cron to a temporary file then adds new lines to the temporary file then copies the entire temporary file back into cron. My second post in this thread is an easier way to add multiple lines to cron... but there is more than one way to accomplish every task.

 

Another thing that is different is that "/var/spool/cron/crontabs/root-" is used instead of "/var/spool/cron/crontabs/root". Some *nix systems will use "-" at the end of a file as a backup file (like passwd- would be the last version of the passwd file). I am not positive that is what the "-" at the end is doing in your linked thread, but I don't use it.

 

What you want can be accomplished with one line in your /boot/config/go file:

echo "25 * * * * /boot/dyndns.sh" >> /var/spool/cron/crontabs/root

Link to comment

Ok. Thank you for the clarification!

 

And thank you for bringing me to unRAID, I immediatley fell in love with your build when I first saw it on the Newznab Forums.  :D

After reading about unRAID it was a matter of mere days before I decided to build myself a Server aswell....

Link to comment

I am completely happy with my decision!

Love playing around with new things.

 

After getting this error message:

 

crond[25752]: unable to exec /usr/sbin/sendmail: cron output for user root /boot/dyndns.sh to /dev/null

 

(which I don´t really get, since I am getting the email-notifications via the SimpleFeatures Plugin just fine)

i added

 >/dev/null

 

to the go file, hopefully disabling email notifications (i dont want them anyway, at least for the crontab)

turning the go file now into:

 

echo "25 * * * * /boot/dyndns.sh >/dev/null" >> /var/spool/cron/crontabs/root

 

This is supposed to ignore stdout and only send warnings and errors to my mailaccount.

Right?

 

 

 

Shouldn´t there be some output in /var/log/cron?

The log is empty....

Link to comment
  • 4 weeks later...

To totally ignore stdout and stderr in cron jobs

 

echo "25 * * * * /boot/dyndns.sh >/dev/null 2>&1 "

 

To direct all cron job output to syslog you can use the following example (which is what I usually use)

All output is captured into /var/log/syslog (You'll need to be careful about how much data you output)

 

25 * * * * /boot/dyndns.sh 2>&1 | /usr/bin/logger -tdyndns.sh[$$]

Link to comment

I am completely happy with my decision!

Love playing around with new things.

 

After getting this error message:

 

crond[25752]: unable to exec /usr/sbin/sendmail: cron output for user root /boot/dyndns.sh to /dev/null

 

(which I don´t really get, since I am getting the email-notifications via the SimpleFeatures Plugin just fine)

i added

 >/dev/null

 

to the go file, hopefully disabling email notifications (i dont want them anyway, at least for the crontab)

turning the go file now into:

 

echo "25 * * * * /boot/dyndns.sh >/dev/null" >> /var/spool/cron/crontabs/root

 

This is supposed to ignore stdout and only send warnings and errors to my mailaccount.

Right?

 

 

 

Shouldn´t there be some output in /var/log/cron?

The log is empty....

unfortunately, SimpleFeatures does not install "sendmail, nor any "mail" command that will forward mail sent to "root" onward.  The "cron" command sends all output from invoked commands through the "mail" command to the "root" user.

 

Joe L.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...