Popular recipes tagged "unix" but not "linux"http://code.activestate.com/recipes/tags/unix-linux/2017-03-01T17:18:23-08:00ActiveState Code RecipesShow OS error codes and messages from the os.errno module (Python)
2017-03-01T17:18:23-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580759-show-os-error-codes-and-messages-from-the-oserrno-/
<p style="color: grey">
Python
recipe 580759
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/introspection/">introspection</a>, <a href="/recipes/tags/libraries/">libraries</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe is a simple Python introspection utility that displays the defined OS error codes and messages (that Python knows about) from the os.errno module. It works for both Python 2 and Python 3. For each kind of OS error defined in Python, it will display a serial number, the error code, and the corresponding error name, and English error message. E.g. the first few lines of its output are shown below:</p>
<p>$ py -2 os_errno_info.py</p>
<p>Showing error codes and names</p>
<p>from the os.errno module:</p>
<p>Python sys.version: 2.7.12</p>
<p>Number of error codes: 86</p>
<p>Idx Code Name Message</p>
<p>0 1 EPERM Operation not permitted</p>
<p>1 2 ENOENT No such file or directory</p>
<p>2 3 ESRCH No such process</p>
<p>3 4 EINTR Interrupted function call</p>
<p>4 5 EIO Input/output error</p>
<p>More information, full output and other details are available here:</p>
<p><a href="https://jugad2.blogspot.in/2017/03/show-error-numbers-and-codes-from.html" rel="nofollow">https://jugad2.blogspot.in/2017/03/show-error-numbers-and-codes-from.html</a></p>
Text ruler for console (record-oriented data processing utility) (Python)
2016-04-17T19:32:26-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580647-text-ruler-for-console-record-oriented-data-proces/
<p style="color: grey">
Python
recipe 580647
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/rulers/">rulers</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple text-based ruler for your command-line console. It can help you find the position of your own program's output on the line, or to find the positions and lengths of fields in fixed- or variable-length records in a text file, fields in CSV files, etc.</p>
Send a message to remote syslog server (Perl)
2014-07-31T17:23:17-07:00Brett Carrollhttp://code.activestate.com/recipes/users/4174322/http://code.activestate.com/recipes/578916-send-a-message-to-remote-syslog-server/
<p style="color: grey">
Perl
recipe 578916
by <a href="/recipes/users/4174322/">Brett Carroll</a>
(<a href="/recipes/tags/perl/">perl</a>, <a href="/recipes/tags/syslog/">syslog</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 2.
</p>
<p>This script allows sending syslog messages to a remote syslog server (UNIX).</p>
Sleepsort with processes and pipes (Python)
2011-06-17T02:37:58-07:00Benjamin Petersonhttp://code.activestate.com/recipes/users/4170802/http://code.activestate.com/recipes/577758-sleepsort-with-processes-and-pipes/
<p style="color: grey">
Python
recipe 577758
by <a href="/recipes/users/4170802/">Benjamin Peterson</a>
(<a href="/recipes/tags/process/">process</a>, <a href="/recipes/tags/sorting/">sorting</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 2.
</p>
<p>Sleepsort is a sorting algorithm that uses the system sleep syscall in a very creative fashion.</p>
<p>This is the same algorithm as <a href="http://code.activestate.com/recipes/577756/">recipe 577756</a> but using *nix processes instead of threads.</p>
Creating a tar archive (without using the tarfile module) (Python)
2010-10-11T06:18:42-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/577422-creating-a-tar-archive-without-using-the-tarfile-m/
<p style="color: grey">
Python
recipe 577422
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/compression/">compression</a>, <a href="/recipes/tags/tar/">tar</a>, <a href="/recipes/tags/unix/">unix</a>).
</p>
<p>Creating a tar file is easy if you read the spec (you can look it up on wikipedia). Not every kind of files are supported (it support regular files, folders ans symlinks) and it's generating archives for the original tar file format (path length are limited to 100 chars, no extended attributes, ...). It wasn't tested very much but it was a fun hack :) ... I cheated just a little by looking at the python tarfile code from the stdlib for the checksum computation.</p>
<p>A tar file is very simple, it's a list of header/payload for each entry (file|folder|symlink) you want to archive. There's only a payload for file contents. The header is 512 bytes long and can be written in ascii. Numbers (attributes) needs to be written in octal. The files themselves needs to be written in chunks of 512 bytes, which mean you have to fill the last chunk with zeros when the file size is not a multiple of 512 bytes.</p>
<p>Use it like that: </p>
<pre class="prettyprint"><code>python batar.py /tmp/foo.tar `find .` && tar tf /tmp/foo.tar # or xf if you want to extract it
</code></pre>
Relative path from one directory to another without explicit string functions (unix only) (Python)
2011-04-11T13:02:32-07:00Denis Barmenkovhttp://code.activestate.com/recipes/users/57155/http://code.activestate.com/recipes/577356-relative-path-from-one-directory-to-another-withou/
<p style="color: grey">
Python
recipe 577356
by <a href="/recipes/users/57155/">Denis Barmenkov</a>
(<a href="/recipes/tags/path/">path</a>, <a href="/recipes/tags/relative/">relative</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 4.
</p>
<p>I saw a <a href="http://code.activestate.com/recipes/208993/">recipe 208993</a> messed up with os.sep and '../' and decide to write near-pure-Python version.
os.sep used in string expressions only for testing for root directory.</p>
<p>Function deal with Unix paths (root: "/"), Windows systems are not supported (root: "C:\").</p>
tgraph - Simple ASCII graphing utility (Python)
2011-07-28T21:13:23-07:00Drew Gulinohttp://code.activestate.com/recipes/users/4119417/http://code.activestate.com/recipes/577077-tgraph-simple-ascii-graphing-utility/
<p style="color: grey">
Python
recipe 577077
by <a href="/recipes/users/4119417/">Drew Gulino</a>
(<a href="/recipes/tags/ascii/">ascii</a>, <a href="/recipes/tags/graph/">graph</a>, <a href="/recipes/tags/log/">log</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/tail/">tail</a>, <a href="/recipes/tags/unix/">unix</a>).
</p>
<p>Takes a stream of numbers and outputs simple ASCII graphs of those numbers</p>
touch (Python)
2009-09-28T16:19:23-07:00Trent Mickhttp://code.activestate.com/recipes/users/4173505/http://code.activestate.com/recipes/576915-touch/
<p style="color: grey">
Python
recipe 576915
by <a href="/recipes/users/4173505/">Trent Mick</a>
(<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/touch/">touch</a>, <a href="/recipes/tags/unix/">unix</a>).
</p>
<p>Python function a la the Unix <code>touch</code> program (<a href="http://www.manpagez.com/man/1/touch/">man touch</a>).</p>
unix subprocess wrapper (Python)
2008-07-29T07:11:17-07:00Pádraig Bradyhttp://code.activestate.com/recipes/users/1890175/http://code.activestate.com/recipes/576387-unix-subprocess-wrapper/
<p style="color: grey">
Python
recipe 576387
by <a href="/recipes/users/1890175/">Pádraig Brady</a>
(<a href="/recipes/tags/group/">group</a>, <a href="/recipes/tags/popen/">popen</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 2.
</p>
<p>I have used this for ages to control child processes (and all their children). Some of the existing subprocess module was based on this, but I find this simpler for my uses at least.</p>
<h4>Example:</h4>
<pre class="prettyprint"><code>import subProcess
process = subProcess.subProcess("your shell command")
process.read() #timeout is optional
handle(process.outdata, process.errdata)
del(process)
</code></pre>
Listing the package/patches dependencies of a binary on Solaris (Python)
2008-07-30T04:30:44-07:00Benjamin Sergeanthttp://code.activestate.com/recipes/users/4039626/http://code.activestate.com/recipes/576397-listing-the-packagepatches-dependencies-of-a-binar/
<p style="color: grey">
Python
recipe 576397
by <a href="/recipes/users/4039626/">Benjamin Sergeant</a>
(<a href="/recipes/tags/solaris/">solaris</a>, <a href="/recipes/tags/system/">system</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 2.
</p>
<p>Print (1) packages used by a binary, and (2) the list of installed patches
related to these packages. If you have a binary that works with Solaris 10 update N, but doesn't with Solaris 10 update N-2, run this script on both platform and it will help you to find the patches you're looking for.</p>
<p>(1) is retrieved:</p>
<ul>
<li>By using pldd(pid) on the process you want to trace to get a list of loaded
shared library </li>
<li>By retrieving in the main /var/sadm/install/contents database
the list of package related to these shared libraries</li>
</ul>
<p>(2) is retrieved by parsing the output of the showrev -p command, given as
input of this script</p>