Most viewed recipes tagged "sysadmin"http://code.activestate.com/recipes/tags/sysadmin/views/2009-12-18T15:33:58-08:00ActiveState Code RecipesGet the path of the currently executing python script using import. (Python) 2006-02-24T05:23:36-08:00Jitender Cheemahttp://code.activestate.com/recipes/users/2790517/http://code.activestate.com/recipes/474083-get-the-path-of-the-currently-executing-python-scr/ <p style="color: grey"> Python recipe 474083 by <a href="/recipes/users/2790517/">Jitender Cheema</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <h4>1. sys.arg has the script name</h4> <h4>2. Although there can be many ways, e.g. os.cwd() but, there is another</h4> <h4>trick to</h4> <h4>obtain the Complete URI or Location of the current script.</h4> <h4>You can argue, os.getcwd()</h4> <h4>import can give you working directory of the current script</h4> <h4>Third party Java code calling your script.... ;)</h4> <p>#</p> getch()-like unbuffered character reading from stdin on both Windows and Unix (Python) 2003-01-07T02:31:32-08:00Danny Yoohttp://code.activestate.com/recipes/users/98032/http://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/ <p style="color: grey"> Python recipe 134892 by <a href="/recipes/users/98032/">Danny Yoo</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 2. </p> <p>A small utility class to read single characters from standard input, on both Windows and UNIX systems. It provides a getch() function-like instance.</p> How to Set Environment Variables (Python) 2002-10-27T15:35:32-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/159462-how-to-set-environment-variables/ <p style="color: grey"> Python recipe 159462 by <a href="/recipes/users/178123/">Raymond Hettinger</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Writes environment variables using a batch file wrapper. Overcomes an operating system limitation.</p> Find a file given a search path (Python) 2001-03-09T23:48:58-08:00Chui Teyhttp://code.activestate.com/recipes/users/98139/http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/ <p style="color: grey"> Python recipe 52224 by <a href="/recipes/users/98139/">Chui Tey</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Given search paths separated by a separator, find the first file that matches a given specification.</p> Module to allow Asynchronous subprocess use on Windows and Posix platforms (Python) 2006-12-01T17:30:02-08:00Josiah Carlsonhttp://code.activestate.com/recipes/users/1241800/http://code.activestate.com/recipes/440554-module-to-allow-asynchronous-subprocess-use-on-win/ <p style="color: grey"> Python recipe 440554 by <a href="/recipes/users/1241800/">Josiah Carlson</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 10. </p> <p>The 'subprocess' module in Python 2.4 has made creating and accessing subprocess streams in Python relatively convenient for all supported platforms, but what if you want to interact with the started subprocess? That is, what if you want to send a command, read the response, and send a new command based on that response?</p> <p>Now there is a solution. The included subprocess.Popen subclass adds three new commonly used methods: recv(maxsize=None), recv_err(maxsize=None), and send(input), along with a utility method: send_recv(input='', maxsize=None).</p> <p>recv() and recv_err() both read at most maxsize bytes from the started subprocess. send() sends strings to the started subprocess. send_recv() will send the provided input, and read up to maxsize bytes from both stdout and stderr.</p> <p>If any of the pipes are closed, the attributes for those pipes will be set to None, and the methods will return None.</p> <p>v. 1.3 fixed a few bugs relating to *nix support v. 1.4,5 fixed initialization on all platforms, a few bugs relating to Windows support, added two utility functions, and added an example of how to use this module. v. 1.6 fixed linux _recv() and test initialization thanks to Yuri Takhteyev at Stanford. v. 1.7 removed _setup() and __init__() and fixed subprocess unittests thanks to Antonio Valentino. Added 4th argument 'tr' to recv_some(), which is, approximately, the number of times it will attempt to recieve data. Added 5th argument 'stderr' to recv_some(), where when true, will recieve from stderr. Cleaned up some pipe closing. v. 1.8 Fixed missing self. parameter in non-windows _recv method thanks to comment. v. 1.9 Fixed fcntl calls for closed handles.</p> Terminating a subprocess on Windows (Python) 2004-11-24T12:52:28-08:00Jimmy Retzlaffhttp://code.activestate.com/recipes/users/98735/http://code.activestate.com/recipes/347462-terminating-a-subprocess-on-windows/ <p style="color: grey"> Python recipe 347462 by <a href="/recipes/users/98735/">Jimmy Retzlaff</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>The new subprocess module in Python 2.4 (also available for 2.2 and 2.3 at <a href="http://effbot.org/downloads/#subprocess" rel="nofollow">http://effbot.org/downloads/#subprocess</a>) allows access to the handle of any newly created subprocess. You can use this handle to terminate subprocesses using either ctypes or the pywin32 extensions.</p> Pyline: a grep-like, sed-like command-line tool. (Python) 2006-03-30T14:50:24-08:00Graham Fawcetthttp://code.activestate.com/recipes/users/108898/http://code.activestate.com/recipes/437932-pyline-a-grep-like-sed-like-command-line-tool/ <p style="color: grey"> Python recipe 437932 by <a href="/recipes/users/108898/">Graham Fawcett</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 3. </p> <p>This utility was born from the fact that I keep forgetting how to use "sed", and I suck at Perl. It brings ad-hoc command-line piping sensibilities to the Python interpeter. (Version 1.2 does better outputting of list-like results, thanks to Mark Eichin.)</p> Persistent environment variables on Windows (Python) 2007-07-24T18:46:47-07:00Gigi Sayfanhttp://code.activestate.com/recipes/users/101538/http://code.activestate.com/recipes/416087-persistent-environment-variables-on-windows/ <p style="color: grey"> Python recipe 416087 by <a href="/recipes/users/101538/">Gigi Sayfan</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 4. </p> <p>This script allows adding/modifying/removing environment variables persistently on Windows. It also allows adding entries to the PATH environment variable.</p> a friendly mkdir() (Python) 2009-12-18T15:33:58-08:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/82465-a-friendly-mkdir/ <p style="color: grey"> Python recipe 82465 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 4. </p> <p>A more friendly mkdir() than Python's standard os.mkdir(). Limitations: it doesn't take the optional 'mode' argument yet.</p> Remote control with telnetlib (Python) 2001-03-11T11:29:37-08:00Jeff Bauerhttp://code.activestate.com/recipes/users/98055/http://code.activestate.com/recipes/52228-remote-control-with-telnetlib/ <p style="color: grey"> Python recipe 52228 by <a href="/recipes/users/98055/">Jeff Bauer</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Send commands to one or more logins using Python's standard telnetlib module.</p> List information about installed Python packages and modules (Python) 2005-09-02T06:53:56-07:00Anand Pillaihttp://code.activestate.com/recipes/users/2499592/http://code.activestate.com/recipes/440501-list-information-about-installed-python-packages-a/ <p style="color: grey"> Python recipe 440501 by <a href="/recipes/users/2499592/">Anand Pillai</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 3. </p> <p>This recipe provides a quick way to search and retrieve information about installed Python packages and modules in your Python installation. It classifies the retrieved module information into types (built-in, source files, c-extensions etc) and prints module information under each type as a sorted list.</p> Manipulating Windows Services (Python) 2001-05-30T18:01:14-07:00andy mckayhttp://code.activestate.com/recipes/users/92886/http://code.activestate.com/recipes/59872-manipulating-windows-services/ <p style="color: grey"> Python recipe 59872 by <a href="/recipes/users/92886/">andy mckay</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>Its easy to mess with Windows Service using Python.</p> Random Password Generation (Python) 2001-05-31T08:10:02-07:00Devin Leunghttp://code.activestate.com/recipes/users/111400/http://code.activestate.com/recipes/59873-random-password-generation/ <p style="color: grey"> Python recipe 59873 by <a href="/recipes/users/111400/">Devin Leung</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>This is a code snippet to generate an 8 character alphanumeric password.</p> Parsing the command line (Python) 2004-04-18T08:15:21-07:00Michele Simionatohttp://code.activestate.com/recipes/users/1122360/http://code.activestate.com/recipes/278844-parsing-the-command-line/ <p style="color: grey"> Python recipe 278844 by <a href="/recipes/users/1122360/">Michele Simionato</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 2. </p> <p>The module optparse was a great addition to Python 2.3, since it is much more powerful and easier to use than getopt. Using optparse, writing command-line tools is a breeze. However, the power of optparse comes together with a certain verbosity. This recipe allows to use optparse with a minimum of boilerplate, trading flexibility for easy of use. Still, it covers 95% of my common needs, so I think it may be useful to others.</p> changing file attributes on windows (Python) 2004-09-03T11:54:59-07:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/303343-changing-file-attributes-on-windows/ <p style="color: grey"> Python recipe 303343 by <a href="/recipes/users/135654/">John Nielsen</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>The win32api module offers SetFileAttributes whiles allows you to make changes to a file in windows. You can set a file to be read only, archive, hidden, etc. The function is simple and convenient to use.</p> To Find out the Hard Disk Size,Free Space and Used Space of a Networked Computer (Python) 2001-07-31T12:39:56-07:00Ratnakar Mallahttp://code.activestate.com/recipes/users/122994/http://code.activestate.com/recipes/66455-to-find-out-the-hard-disk-sizefree-space-and-used-/ <p style="color: grey"> Python recipe 66455 by <a href="/recipes/users/122994/">Ratnakar Malla</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>This module , does not take any i/p file. It first does a net view command , and gets the list of computers in the domain. Connects to each computer , performs size check and returns the size of the harddisk. Please note that , the file and dir sizes are caluclated in DOS. Windows performs a sort of approximation. So there will be slight variation in the amount of space reported by DOS and Windows. If I am not wrong DOS gives u the best values.</p> Memory usage. (Python) 2004-07-11T09:59:03-07:00Jean Brouwershttp://code.activestate.com/recipes/users/1294974/http://code.activestate.com/recipes/286222-memory-usage/ <p style="color: grey"> Python recipe 286222 by <a href="/recipes/users/1294974/">Jean Brouwers</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>This recipe provides a number of functions to get the memory usage of a Python application on Linux.</p> Change Windows Console Character Attribute (Color) (Python) 2006-07-20T18:25:17-07:00Randyhttp://code.activestate.com/recipes/users/2058394/http://code.activestate.com/recipes/496901-change-windows-console-character-attribute-color/ <p style="color: grey"> Python recipe 496901 by <a href="/recipes/users/2058394/">Randy</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 3. </p> <p>A simple function to change the background/foreground color of characters written to a Windows console (command line). Requires ctypes, which is included with Python version 2.5 or later.</p> getting process information on windows (Python) 2004-09-03T11:10:53-07:00John Nielsenhttp://code.activestate.com/recipes/users/135654/http://code.activestate.com/recipes/303339-getting-process-information-on-windows/ <p style="color: grey"> Python recipe 303339 by <a href="/recipes/users/135654/">John Nielsen</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>To get process information for both NT and W2K (but not the 9x family) you can use the Performance Data Helper library(PDH). The is a simple example that shows you how to get a process list and their ids. It provides a convenient interface to performance information stored fundamentally in the registry. The basic process of using the PDH encompasses the following:</p> <ol> <li>Get a list of all the objects you want</li> <li>Get a list of the object's instances and data available for each instance: called 'items' or 'counters'</li> <li>Get a group of performance data for each counter</li> </ol> <p>In the case here we want the process object, the object's instances are it's list of processes, and the counter we want for the processes is 'ID Process'.</p> Reading and writing mbox style mailbox files. (Python) 2002-10-18T12:06:30-07:00Noah Spurrierhttp://code.activestate.com/recipes/users/103276/http://code.activestate.com/recipes/157437-reading-and-writing-mbox-style-mailbox-files/ <p style="color: grey"> Python recipe 157437 by <a href="/recipes/users/103276/">Noah Spurrier</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). </p> <p>This script demonstrates reading and writing an mbox style mailbox. This script is an mbox filter. It scans through an entire mbox and writes the messages to a new file. Each message is passed through a filter function which may modify the document or ignore it.</p>