Popular recipes tagged "unix" but not "windows"http://code.activestate.com/recipes/tags/unix-windows/2017-01-08T17:48:57-08:00ActiveState Code RecipesA utility like Unix seq (command-line), in Python (Python) 2017-01-08T17:48:57-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580744-a-utility-like-unix-seq-command-line-in-python/ <p style="color: grey"> Python recipe 580744 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/seq/">seq</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>This recipe shows how to create a utility like Unix seq (command-line), in Python. seq is described here: </p> <p><a href="https://en.wikipedia.org/wiki/Seq_%28Unix%29" rel="nofollow">https://en.wikipedia.org/wiki/Seq_(Unix)</a></p> <p>but briefly, it is a command-line utility that takes 1 to 3 arguments (some being optional), the start, stop and step, and prints numbers from the start value to the stop value, on standard output. So seq has many uses in bigger commands or scripts; a common category of use is to quickly generate multiple filenames or other strings that contain numbers in them, for exhaustive testing, load testing or other purposes. A similar command called jot is found on some Unix systems.</p> <p>This recipe does not try to be exactly the same in functionality as seq. It has some differences. However the core functionality of generating integer sequences is the same (but without steps other than 1 for the range).</p> <p>More details and sample output are here:</p> <p><a href="https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html" rel="nofollow">https://jugad2.blogspot.in/2017/01/an-unix-seq-like-utility-in-python.html</a></p> <p>The code is below.</p> File comparison utility in Python (Python) 2016-03-26T18:31:11-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580631-file-comparison-utility-in-python/ <p style="color: grey"> Python recipe 580631 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/comparison/">comparison</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>). </p> <p>This is a recipe to compare any two files via a Python command-line program. It is like a basic version of the cmp command of Unix or the fc.exe (file compare) command of Windows.</p> Python-controlled Unix pipeline to generate PDF (Python) 2016-01-07T18:02:52-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579146-python-controlled-unix-pipeline-to-generate-pdf/ <p style="color: grey"> Python recipe 579146 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pdf_generation/">pdf_generation</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python2/">python2</a>, <a href="/recipes/tags/unix/">unix</a>). </p> <p>This recipe shows how to create a Unix pipeline that generates PDF output, under the control of a Python program. It is tested on Linux. It uses nl, a standard Linux command that adds line numbers to its input, and selpg, a custom Linux command-line utility, that selects only specified pages from its input, together in a pipeline (nl | selpg). The Python program sets up and starts that pipeline running, and then reads input from it and generates PDF output.</p> A UNIX-like "which" command for Python (Python) 2015-03-20T19:23:45-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579035-a-unix-like-which-command-for-python/ <p style="color: grey"> Python recipe 579035 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/commands/">commands</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/which/">which</a>). </p> <p>UNIX users are familiar with the which command. Given an argument called name, it checks the system PATH environment variable, to see whether that name exists (as a file) in any of the directories specified in the PATH. (The directories in the PATH are colon-separated on UNIX and semicolon-separated on Windows.)</p> <p>This recipe shows how to write a minimal which command in Python. It has been tested on Windows.</p> Print selected text pages to PDF with Python, selpg and xtopdf on Linux (Bash) 2014-10-29T17:38:10-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578954-print-selected-text-pages-to-pdf-with-python-selpg/ <p style="color: grey"> Bash recipe 578954 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/text/">text</a>, <a href="/recipes/tags/text_files/">text_files</a>, <a href="/recipes/tags/text_processing/">text_processing</a>, <a href="/recipes/tags/unix/">unix</a>). </p> <p>This recipe shows how to use selpg, a Linux command-line utility written in C, together with xtopdf, a Python toolkit for PDF creation, to print only a selected range of pages from a text file, to a PDF file, for display or print purposes. The way to do this is to run the selpg utility at the Linux command line, with options specifying the start and end pages of the range, and pipe its output to the StdinToPDF.py program, which is a part of the xtopdf toolkit.</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> Create PDF at the end of a Unix pipeline with PDFWriter (Python) 2013-12-22T22:19:00-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578794-create-pdf-at-the-end-of-a-unix-pipeline-with-pdfw/ <p style="color: grey"> Python recipe 578794 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/pdf/">pdf</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/reportlab/">reportlab</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/xtopdf/">xtopdf</a>). </p> <p>This recipe shows how to create PDF output at the end of a Unix or Linux pipeline, after all the text processing required, is done by previous components of the pipeline (which can use any of the standard tools of Unix such as sed, grep, awk, etc., as well as custom programs that act as filters).</p> PostgreSQL database backup script (Python) 2011-07-15T08:27:05-07:00Evgeniy.Khttp://code.activestate.com/recipes/users/4178635/http://code.activestate.com/recipes/577793-postgresql-database-backup-script/ <p style="color: grey"> Python recipe 577793 by <a href="/recipes/users/4178635/">Evgeniy.K</a> (<a href="/recipes/tags/backup/">backup</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/postgresql/">postgresql</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/unix/">unix</a>). </p> <p>Simple script to backup some databases from PostgreSQL on unix\linux.</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> Get additional group IDs for Unix user (pwd/grp modules) (Python) 2011-06-03T02:14:18-07:00realityexistshttp://code.activestate.com/recipes/users/4178189/http://code.activestate.com/recipes/577733-get-additional-group-ids-for-unix-user-pwdgrp-modu/ <p style="color: grey"> Python recipe 577733 by <a href="/recipes/users/4178189/">realityexists</a> (<a href="/recipes/tags/group/">group</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/passwd/">passwd</a>, <a href="/recipes/tags/security/">security</a>, <a href="/recipes/tags/unix/">unix</a>). </p> <p>The Python stdlib pwd module provides an easy way to get the primary group ID, but no way to get additional group IDs. This is a simple function that returns the additional group IDs for a given username.</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 .` &amp;&amp; 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> Linux Terminal Color Setter (Python) 2008-09-11T17:08:30-07:00Collin Stockshttp://code.activestate.com/recipes/users/4149235/http://code.activestate.com/recipes/576503-linux-terminal-color-setter/ <p style="color: grey"> Python recipe 576503 by <a href="/recipes/users/4149235/">Collin Stocks</a> (<a href="/recipes/tags/just_for_fun/">just_for_fun</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/terminal/">terminal</a>, <a href="/recipes/tags/unix/">unix</a>). </p> <p>This module can move the cursor around in the terminal, change the text color, highlighting color, et cetera, bold, underlined, flashing (if supported). It also has a word wrap function, and can center text.</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>