Most viewed recipes tagged "unix"http://code.activestate.com/recipes/tags/unix/views/2017-03-31T14:30:30-07:00ActiveState Code RecipesSimple command-line alarm clock in Python (Python)
2015-10-25T18:27:27-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579117-simple-command-line-alarm-clock-in-python/
<p style="color: grey">
Python
recipe 579117
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/clock/">clock</a>, <a href="/recipes/tags/commandline/">commandline</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/time/">time</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple alarm clock in Python, that can be run from the command line in a terminal. It lets you specify the alarm time in minutes as a command line argument, and prints a wake-up message and beeps a few times, after that time arrives. You can use 0 for the minutes to test it immediately, including to adjust the volume using your speaker controls.</p>
Unix tee-like functionality via a Python class (Python)
2017-03-31T14:30:30-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580767-unix-tee-like-functionality-via-a-python-class/
<p style="color: grey">
Python
recipe 580767
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/cli/">cli</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/python/">python</a>, <a href="/recipes/tags/tee/">tee</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>The Unix tee commmand, when used in a command pipeline, allows you to capture the output of the preceding command to a file or files, while still sending it on to standard output (stdout) for further processing via other commands in a pipeline, or to print it, etc.</p>
<p>This recipe shows how to implement simple tee-like functionality via a Python class. I do not aim to exactly replicate the functionality of the Unix tee, only something similar.</p>
<p>More details and sample output here:</p>
<p><a href="https://jugad2.blogspot.in/2017/03/a-python-class-like-unix-tee-command.html" rel="nofollow">https://jugad2.blogspot.in/2017/03/a-python-class-like-unix-tee-command.html</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>
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>
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>
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>
A binary file split utility in Python (Python)
2016-04-07T18:19:35-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580637-a-binary-file-split-utility-in-python/
<p style="color: grey">
Python
recipe 580637
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/commandline/">commandline</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/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple binary file split utility in Python.</p>
<p>It takes two command line arguments: 1) the name of the input file to split , 2) the number of bytes per file into which to split the input.</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>
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>
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>
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>
JavaScript WebSocket client for Python + Go WebSocket-based system monitoring example (JavaScript)
2014-01-03T21:09:54-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/578806-javascript-websocket-client-for-python-go-websocke/
<p style="color: grey">
JavaScript
recipe 578806
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/golang/">golang</a>, <a href="/recipes/tags/javascript/">javascript</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/sysadmin/">sysadmin</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/websockets/">websockets</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe is the JavaScript client side of an overall recipe that shows how to do system monitoring using WebSockets, Python, Go (using websocketd), and JavaScript + HTML. The server side of the recipe (in Python, and using websocketd which is written in Go), is here:</p>
<p><a href="http://code.activestate.com/recipes/578803-using-websocketd-with-python-for-web-based-system-/?in=user-4173351" rel="nofollow">http://code.activestate.com/recipes/578803-using-websocketd-with-python-for-web-based-system-/?in=user-4173351</a></p>
<p>The system monitoring example shows the system disk space info (total, used and free) using the Python psutil module.</p>
Show 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>
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>
data_dump.py, like the Unix od (octal dump) command (Python)
2015-11-01T12:43:38-08:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/579120-data_dumppy-like-the-unix-od-octal-dump-command/
<p style="color: grey">
Python
recipe 579120
by <a href="/recipes/users/4173351/">Vasudev Ram</a>
(<a href="/recipes/tags/data/">data</a>, <a href="/recipes/tags/dump/">dump</a>, <a href="/recipes/tags/hexadecimal/">hexadecimal</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/octal/">octal</a>, <a href="/recipes/tags/od/">od</a>, <a href="/recipes/tags/representation/">representation</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe implements a simple data dump tool, roughly like the od command of Unix, which stands for octal dump (though od can also dump data in hex and other formats). This tool dumps data in character and hex formats, in this version. This is data_dump.py version 1.</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>
A 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>
Unix-like split command in Python (simple version) (Python)
2016-03-14T22:35:05-07:00Vasudev Ramhttp://code.activestate.com/recipes/users/4173351/http://code.activestate.com/recipes/580620-unix-like-split-command-in-python-simple-version/
<p style="color: grey">
Python
recipe 580620
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/python/">python</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/split/">split</a>, <a href="/recipes/tags/splitting/">splitting</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>This recipe shows how to create a simple version of the Unix split command in Python. The split command splits an input file into multiple smaller files, the size of each of which is specified by a command-line argument giving the number of lines per file. This is useful for multiple purposes, such as editing large files in pieces, backing up files to small capacity storage devices, sending files across the network, etc.</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>
A pseudo-echo, (or printf), function for any Python version. (Python)
2017-01-20T22:17:23-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/580750-a-pseudo-echo-or-printf-function-for-any-python-ve/
<p style="color: grey">
Python
recipe 580750
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/amiga/">amiga</a>, <a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/demo/">demo</a>, <a href="/recipes/tags/echo/">echo</a>, <a href="/recipes/tags/fs_uae/">fs_uae</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/printf/">printf</a>, <a href="/recipes/tags/unix/">unix</a>, <a href="/recipes/tags/windows/">windows</a>, <a href="/recipes/tags/winuae/">winuae</a>).
</p>
<p>A simple example of having a pseudo-echo using sys.stdout.write...</p>
<p>This gives exactly the same results from Python Versions, 1.4.0, 2.0.1, 2.5.6, 2.6.9, 3.4.3 and 3.5.2 on various platforms including the classic AMIGA A1200.</p>
<p>Enjoy finding simple solutions to often very difficult problems...</p>
<p>Bazza.</p>