[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using at to restart dhcp server



On 20/10/2011 12:07 AM, Andrew McGlashan wrote:
Hi,

On 19/10/2011 11:45 PM, Bonno Bloksma wrote:
Using Debian Lenny I want to restart my dhcp server tonight at 7pm using
the at command so I enter:
at 7pm /etc/init.d/dhcp3-server restart
and get
syntax error. last token seen: /
The same for
at 7pm "/etc/init.d/dhcp3-server restart"


# at 7pm <<EOF
 > /etc/init.d/dhcp3-server restart
 > EOF
warning: commands will be executed using /bin/sh
job 13 at Thu Oct 20 19:00:00 2011

As has been demonstrated, there are usually more than one way to "skin a cat", so to speak ;-)

If you were a computer teacher, then perhaps this shouldn't have been so hard? Anyway, sorry I wasn't specific enough. I do often say that computing has a very broad range of different skills, just like many other professions and it's hard [or rather impossible, really] to be a master of all areas.

You could also create a script like the following and call that whenever you want to schedule the job. Or you can regularly run it at 7pm each Monday through Friday via cron using an /etc/crontab entry.

Script:

#!/bin/bash

at 7pm <<EOF
/etc/init.d/dhcp3-server restart
EOF


Now the <<EOF means accept input right up to the next occurrence of EOF and then you are done. EOF can be any combination of characters. Each line of "code" or "instruction" for the job should normally start at the beginning of each line until the terminator (EOF in the above case), which remains on a line of it's own to finish things off.



Or as has been mentioned, it could just as easily be:


#!/bin/bash

echo "/etc/init.d/dhcp3-server restart"|at 7pm


The #!/bin/bash line means, use this shell to action (run) the script.

If you create a script, then it would probably be the "best" thing to make it executable and you may want to make it owned by root and only be allowed to run as root.

chown root:root scriptname.sh
chmod 700 scriptname.sh

Given the type of action, you probably only want to run this script as root. 700 means that the owner has read, write and execute permissions, whilst group and other has no permissions.

And you probably want to place this script in your own sbin directory, such as /usr/local/sbin/ which might be a path entry for root user, but not for ordinary users; or perhaps your *really* own sbin directory at:
    ~yourusername/sbin


A crontab entry might look like this:

19 *    * * 1-5   root    /etc/init.d/dhcp3-server restart


You may want to replace an actual "single" command as above with a script. Like this:

19 *    * * 1-5   root    /usr/local/sbin/scriptname.sh


Such a crontab entry will run at 7pm each Monday through Friday (1 is for Monday, - means inclusive range and 5 is for Friday. Crontab entries normally must be contained to one line, ie no line continuation; blank or empty lines can be a problem with some OS types, read Solaris at least.

And to expand just a little further, if you have particular users whom might want to run the script, then consider a fully pathed sudo option for them. You can research sudo now if you wish .... ;-)


Using crontab (cron) or not may depend on what is actually installed and available for you. There are all sorts of "cron like" options to consider as well. I won't go into all those options, suffice to say that man is your friend, just like Google is for many too.

Any "at" entries can be listed with "at -l" and entries can be deleted using their "job" number, such as "at -d 3".

All at jobs are stored as a script of their own in:
   /var/spool/cron/atjobs

 [notice the similarities to cron for at? .... ]


I hope this post is _more_ educational and easier to understand.

Thanks and Cheers.

--
Kind Regards
AndrewM

Andrew McGlashan
Broadband Solutions now including VoIP

Current Land Line No: 03 9012 2102
Mobile: 04 2574 1827 Fax: 03 9012 2178

National No: 1300 85 3804

Affinity Vision Australia Pty Ltd
http://www.affinityvision.com.au
http://adsl2choice.net.au

In Case of Emergency --  http://www.affinityvision.com.au/ice.html


Reply to: