# reboot FreeBSD box with crontab



## mfaridi (Oct 14, 2011)

I have three FreeBSD box and have problem with all of thenm and I describe it in this topic
http://forums.freebsd.org/showthread.php?t=26976

So I have to ssh to my system before 26 hours and reboot them by command , so I want reboot my system every 24 housrs by crontab , how I can do this ?
I want reboot system by crontab .


----------



## johnd (Oct 14, 2011)

Hello mfaridi.

To do a scheduled reboot at midnight put to following code into the system contrab file /etc/crontab

```
@midnight root /sbin/shutdown -r now
```
I have not tested this, but it should work. For more information see crontab(5)


----------



## wblock@ (Oct 14, 2011)

`# shutdown -r now`
is preferred because it allows services to stop cleanly.

Fixing the problem is better yet.  Clearly it's not a hardware problem.  With extra machines, finding the software problem shouldn't be too hard.  Set up one machine for a test, make sure it crashes on schedule, change one thing at a time until it doesn't crash on schedule.


----------



## Alt (Oct 14, 2011)

Better if you will do
	
	



```
shutdown -r +5
```
This will broadcast to users about reboot in 5minutes, so they can save their work


----------



## mfaridi (Oct 14, 2011)

thanks all guys , but my server is NAT and samba server and I want reboot in midnight when nobody work  with their system and and they are in house . if I find way to solve this problem it is better than reboot system before 26  hours


----------



## mfaridi (Oct 14, 2011)

wblock@ said:
			
		

> `# shutdown -r now`
> is preferred because it allows services to stop cleanly.
> 
> Fixing the problem is better yet.  Clearly it's not a hardware problem.  With extra machines, finding the software problem shouldn't be too hard.  Set up one machine for a test, make sure it crashes on schedule, change one thing at a time until it doesn't crash on schedule.



Do you think reboot system with  crontab is not safe and it can make problem for my system ?


----------



## mfaridi (Oct 14, 2011)

how I can check this command work good , 
	
	



```
@midnight root /sbin/shutdown -r now
```
 because I ma far way from FreeBSD server and connect to FreeBSD box with SSH , I go to my work place in tuseday only . I do my all work remotely with ssh


----------



## johnd (Oct 14, 2011)

I have just rebooted my machine this way. It worked fine. I can now login via ssh again. You can use ping(8) to see if your machine is reachable, or use "netcat" to see if your ssh server is listening for connections. Like this:

```
nc -v -n -z 1.2.3.4 22
```
 Or simply login via ssh  
Then you can verify that your machine has rebooted using uptime(1)


----------

