Due to some bugs in CUCM (MTP resources leaking) or some bugs in UCCX (API error 500), we have to periodically reboot the systems.
We can able to automate it by using the Python script.
1. Install 'Ubuntu 20'
![timuryuldashev_0-1671085618211.png timuryuldashev_0-1671085618211.png](https://community.cisco.com/t5/image/serverpage/image-id/171029i727AC3EB44770F88/image-size/medium?v=v2&px=400)
![timuryuldashev_1-1671086077357.png timuryuldashev_1-1671086077357.png](https://community.cisco.com/t5/image/serverpage/image-id/171030iCDF1F41E192A11B7/image-size/medium?v=v2&px=400)
2. Install 'Windows Terminal'
![timuryuldashev_2-1671086265403.png timuryuldashev_2-1671086265403.png](https://community.cisco.com/t5/image/serverpage/image-id/171031iF5531ED6C75A47E9/image-size/medium?v=v2&px=400)
![timuryuldashev_3-1671086306858.png timuryuldashev_3-1671086306858.png](https://community.cisco.com/t5/image/serverpage/image-id/171033i147963CAEF650EE7/image-size/medium?v=v2&px=400)
3. Start the 'Windows Terminal' and open 'Settings'.
![timuryuldashev_4-1671086457191.png timuryuldashev_4-1671086457191.png](https://community.cisco.com/t5/image/serverpage/image-id/171034i230B8A150489F842/image-size/medium?v=v2&px=400)
4. Set 'Default Profile', 'When the Terminal starts' and click Save.
![timuryuldashev_5-1671086885262.png timuryuldashev_5-1671086885262.png](https://community.cisco.com/t5/image/serverpage/image-id/171035i7757A6373704A225/image-dimensions/671x376?v=v2)
5. Set 'Never close automatically' and press 'Save'
![timuryuldashev_6-1671087125001.png timuryuldashev_6-1671087125001.png](https://community.cisco.com/t5/image/serverpage/image-id/171036i61FFF0054B42AB17/image-dimensions/667x375?v=v2)
6. Turn on the 'Windows Subsystem for Linux'
![timuryuldashev_7-1671087306225.png timuryuldashev_7-1671087306225.png](https://community.cisco.com/t5/image/serverpage/image-id/171037i3112D124DF42A9A3/image-dimensions/518x365?v=v2)
7. Start the 'Windows Terminal'.
![timuryuldashev_0-1671092613719.png timuryuldashev_0-1671092613719.png](https://community.cisco.com/t5/image/serverpage/image-id/171090i5364E64601F2F51E/image-dimensions/643x331?v=v2)
8. Create the file reboot.py
![timuryuldashev_1-1671095685305.png timuryuldashev_1-1671095685305.png](https://community.cisco.com/t5/image/serverpage/image-id/171096iBCB1AC149B76F271/image-dimensions/643x331?v=v2)
9. Type the following code
import pexpect
import sys
import time
server_ip = "ccx.winncom.uz"
server_user = "CCXAdm"
server_pass = "ZAQ!2wsx"
child = pexpect.spawn(f'ssh -o "StrictHostKeyChecking=no" {server_user}@{server_ip}',encoding='utf-8')
child.delaybeforesend = 5
child.timeout=1200
child.logfile = sys.stdout
child.expect("CCXAdm@ccx.winncom.uz's password: ")
child.sendline(server_pass)
child.expect('admin:')
child.sendline('utils system restart')
child.expect('Enter (yes/no)?')
child.send('y')
child.send('e')
child.send('s')
child.sendline()
print ('Restart command successfully sent.')
time.sleep(600)
10. For testing type 'python3 reboot.py'
![timuryuldashev_0-1671096782456.png timuryuldashev_0-1671096782456.png](https://community.cisco.com/t5/image/serverpage/image-id/171100iA52E3F09553443D8/image-dimensions/604x311?v=v2)
11. Enable and start cron.
sudo systemctl enable cron
sudo service cron start
12. Check if the cron started.
pgrep cron
13. Setup the cron.
crontab -e
![timuryuldashev_0-1671098169743.png timuryuldashev_0-1671098169743.png](https://community.cisco.com/t5/image/serverpage/image-id/171103iB2FF9125020541B4/image-dimensions/603x312?v=v2)
In this example, the file reboot.py will start every Monday at 3:00 a.m.
14. Give the rights
chmod +x reboot.py