Need to setup a cronjob to restart server every ten hours


How would I go about setting up a crontab to restart my server every ten hours?


  1. Why do you need to do that?

  2. When you say server, what exactly are you referring to (Apache, MySQL, FTP, etc., the box itself)?

Its probably not a good idea, but eh. I don’t have anything to do it every 10 hours, but here is a script I wrote recently to give individual users the same nice directory based cron access root can get. It “remembers” when it last issued commands.

2 notes: I didn’t know what to call it, so every 12 hours is “meridianly”. Also, output text from commands gets fudged. No line breaks.



THISHOUR=$(date +%F-%k)
THISMERIDIAN=$(date +%F-%p)
THISDAY=$(date +%F)
THISWEEK=$(date +%y-%U)
THISMONTH=$(date +%y-%m)

for schedule in hourly meridianly daily weekly monthly; do
	if [ $schedule == hourly ]; then
	elif [ $schedule == meridianly ]; then
	elif [ $schedule == daily ]; then
	elif [ $schedule == weekly ]; then
	elif [ $schedule == monthly ]; then
	if [ -e $command_dir ]; then
		for command in $(ls $command_dir); do
			if [ ! -e $command_dir/$DONE_DIR/$command-$datestring ]; then
				output=`$command_dir/$command 2>&1`
				if [ ! -e $command_dir/$DONE_DIR ]; then
					mkdir $command_dir/$DONE_DIR
				if [ $? -eq 0 ]; then
					rm -f $command_dir/$DONE_DIR/$command-*
					touch $command_dir/$DONE_DIR/$command-$datestring
				if [ -n "$output" ]; then
					echo "    ==========    "
					echo $schedule: $command
					echo $output
					echo ""

The first step is to write a bash script, I know that much :wink:

As for creating a cron I’m not sure how to do that but I’m sure google could tell you :slight_smile:

Hello just the box. It locks up once an a while. Developer suggests to setup a restart to clear out the excess memory for the server.

I’d be leary if the solution was a periodic reboot euser, especially on a linux box. sonicgroup had it right in trying to nail down what exactly was causing the issue. a reboot cronjob is easy but if we can help you with the real problem that may be more helpful :).


In my opinion, and I’m not trying to be hostile, or bash your developer, but you, as the server owner/script user, might want to have your dev take a look at whatever is causing the box to lock up. If it is indeed a script, there’s something wrong - because it takes quite a bit to lock up a *nix box. :wink:

The other problem you may run into - if the box itself locks up, a cron job won’t be able to run and reboot the server. More than likely a hard reboot would be necessary.

I dont see why you ever need to reboot your nix box anyhow? I’ve known of a nix box(s) (server environment) that has running for more than 365days an more without rebooting.

I would seek professional help for someone to take a look at your box because of the questioned incident. Having to restart your box every 10hours is not a production machine i guess?