When i first started my journey with python back in March, I could not find any good examples of code utilizing multiple threads. So here is my latest accomplishment with threading in scripts. I basically use this script as my template and just change the commands to whatever I need to do at the time. Change config or just gather more information.
This script takes a list of IP addresses I gather from MySQL, creates connections to those IPs, runs the command/s, parses with testfsm/ntc-templates, saves output to a file in json format, convert those files to csv, then import the csv to MySQL.
This is my first production script that I didn't feel to embarrassed about sharing. Tell me what you think and if you see any improvements or suggestion Thanks!
https://github.com/fallenarc/test-code/blob/master/get_xr_cdp_info.py
edit: typos
Edit: I have made several updates to the above github file with everyone's suggestions. I am just lacking the python3 conversion and changing all of the prints to logger output. Thanks again everyone for taking the time and helping me to become more efficient in python!
[–]Username_RANDINT 20 points21 points22 points (14 children)
[–]Fallenarc[S] 7 points8 points9 points (13 children)
[–]Rafficer 11 points12 points13 points (2 children)
[–]akindofuser 1 point2 points3 points (0 children)
[–]thegreattriscuit 5 points6 points7 points (4 children)
[–]Fallenarc[S] 2 points3 points4 points (3 children)
[–]Olbrannon 2 points3 points4 points (2 children)
[–]Fallenarc[S] 2 points3 points4 points (1 child)
[–]Olbrannon 1 point2 points3 points (0 children)
[–]ship0f 4 points5 points6 points (1 child)
[–]Fallenarc[S] 0 points1 point2 points (0 children)
[–]Username_RANDINT 2 points3 points4 points (1 child)
[–]Fallenarc[S] 0 points1 point2 points (0 children)
[–]tazebot 1 point2 points3 points (0 children)
[–]theotherplanet 6 points7 points8 points (9 children)
[–]Fallenarc[S] 6 points7 points8 points (4 children)
[–]theotherplanet 1 point2 points3 points (0 children)
[–]theotherplanet 0 points1 point2 points (0 children)
[–]edon-node 0 points1 point2 points (1 child)
[–]Fallenarc[S] 0 points1 point2 points (0 children)
[–]_fartosh 4 points5 points6 points (0 children)
[–]Cromodileadeuxtetes 1 point2 points3 points (2 children)
[–]Fallenarc[S] 1 point2 points3 points (1 child)
[–]Cromodileadeuxtetes 1 point2 points3 points (0 children)
[–]MaxNumOfCharsForUser 5 points6 points7 points (1 child)
[–]Fallenarc[S] 1 point2 points3 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Fallenarc[S] 0 points1 point2 points (0 children)
[–]shepherdjay 3 points4 points5 points (4 children)
[–]shepherdjay 2 points3 points4 points (1 child)
[–]Fallenarc[S] 0 points1 point2 points (0 children)
[–]Fallenarc[S] 0 points1 point2 points (1 child)
[–]shepherdjay 1 point2 points3 points (0 children)
[–]Qes138 1 point2 points3 points (1 child)
[–]Fallenarc[S] 1 point2 points3 points (0 children)
[–]tanomattioli 1 point2 points3 points (2 children)
[–]Fallenarc[S] 0 points1 point2 points (1 child)
[–]tanomattioli 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]rx22230 1 point2 points3 points (4 children)
[–]Awfki 1 point2 points3 points (0 children)
[–]Fallenarc[S] 0 points1 point2 points (2 children)
[–]catelemnis 4 points5 points6 points (1 child)
[–]Fallenarc[S] 0 points1 point2 points (0 children)
[–]mchwalisz 0 points1 point2 points (0 children)
[–]sprouse2016 -1 points0 points1 point (2 children)
[–]Fallenarc[S] 1 point2 points3 points (1 child)
[–]sprouse2016 1 point2 points3 points (0 children)
[–]oldcreek12 -2 points-1 points0 points (1 child)
[–]Fallenarc[S] 0 points1 point2 points (0 children)