cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
266
Views
10
Helpful
0
Comments
timuryuldashev
Spotlight
Spotlight

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_1-1671086077357.png

2. Install 'Windows Terminal'

timuryuldashev_2-1671086265403.png

timuryuldashev_3-1671086306858.png

3. Start the 'Windows Terminal' and open 'Settings'.

timuryuldashev_4-1671086457191.png

4. Set 'Default Profile', 'When the Terminal starts' and click Save.

timuryuldashev_5-1671086885262.png

5. Set 'Never close automatically' and press 'Save'

timuryuldashev_6-1671087125001.png

6. Turn on the 'Windows Subsystem for Linux'

timuryuldashev_7-1671087306225.png

7. Start the 'Windows Terminal'.

timuryuldashev_0-1671092613719.png

8. Create the file reboot.py

timuryuldashev_1-1671095685305.png

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

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

In this example, the file reboot.py will start every Monday at 3:00 a.m.

14. Give the rights

chmod +x reboot.py

 

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: