Most viewed recipes tagged "script" Code RecipesBash script to create a header for Bash scripts (Bash) 2011-11-02T01:57:07-07:00userend <p style="color: grey"> Bash recipe 577862 by <a href="/recipes/users/4179007/">userend</a> (<a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/gpl/">gpl</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/vim/">vim</a>). Revision 3. </p> <p>This will create a header for a Bash script. It is a nice way keep a track of what your script does and when it was created, the author of the script, etc.. </p> <p>It will open the script automatically with one of the two most popular editor out there, Vim or Emacs! It also checks to see if there is a script with the same name in the current working directory so it will not overwrite another file.</p> <p>v0.4: I had to kick this up a notch. I took the suggestion of "dev h" to add a chance for the user to select another name for the script.</p> <p>Please leave comments and suggestions.</p> Python script to create a header for Python scripts (Python) 2011-10-02T15:45:11-07:00userend <p style="color: grey"> Python recipe 577846 by <a href="/recipes/users/4179007/">userend</a> (<a href="/recipes/tags/2/">2</a>, <a href="/recipes/tags/auto/">auto</a>, <a href="/recipes/tags/create/">create</a>, <a href="/recipes/tags/emacs/">emacs</a>, <a href="/recipes/tags/header/">header</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/vim/">vim</a>). Revision 5. </p> <p>This will create a header for a Python script. It is a nice way keep a track of what your script does and when it was created, the author of the script, etc.. </p> <p>Update: Now, it will automatically open with one of the two most popular editors, Vim or Emacs! This script has been updated from the second version to replace spaces with underscores in the title, to convert uppercase to lowercase. It also checks to see if there is a script with the same name in the current working directory so it will not overwrite another file. Please leave comments and suggestions.</p> Shutdown your computer via E-mail - Python (Python) 2016-05-27T05:28:21-07:00Burak Tandogan <p style="color: grey"> Python recipe 580668 by <a href="/recipes/users/4191373/">Burak Tandogan</a> (<a href="/recipes/tags/computer/">computer</a>, <a href="/recipes/tags/email/">email</a>, <a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shutdown/">shutdown</a>). Revision 2. </p> <p>Shutdown your computer via E-mail.</p> <p>Basically, send an e-mail to your e-mail address SHUTDOWN YOURSELF {YEAR-MONTH-DATE} format in Subject. Your mail's SUBJECT must be in SHUTDOWN YOURSELF {YEAR-MONTH-DATE} format.</p> Python script main line for graceful exception handling and logging (Python) 2010-09-11T05:46:59-07:00Trent Mick <p style="color: grey"> Python recipe 577258 by <a href="/recipes/users/4173505/">Trent Mick</a> (<a href="/recipes/tags/error/">error</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/main/">main</a>, <a href="/recipes/tags/mainline/">mainline</a>, <a href="/recipes/tags/script/">script</a>). Revision 5. </p> <p>This is a recipe is often use for the mainline of my Python scripts. With this recipe your Python script will:</p> <ul> <li>gracefully handle <code>Ctrl+C</code> (i.e. <code>KeyboardInterrupt</code>)</li> <li>log an error (using the <code>logging</code> module) for uncaught exceptions, importantly <strong>with the file and line number</strong> in your Python code where the exception was raised</li> <li>gracefully ignore a closed output pipe (common when the user pipes your script through <code>less</code> and terminates that)</li> <li>if your script logger is enabled for <code>DEBUG</code> level logging, a full traceback will be shown for an uncaught exception</li> </ul> <p>Presumptions:</p> <ul> <li><p>you have a global <code>log</code> variable a la:</p> <pre class="prettyprint"><code>import logging log = logging.setLevel("scriptname") </code></pre></li> <li><p>your script's entry point is a function <code>def main(argv): ...</code></p></li> </ul> Better quote module for bash shells (Python) 2010-12-03T09:16:45-08:00Kevin L. Sitze <p style="color: grey"> Python recipe 577483 by <a href="/recipes/users/4173535/">Kevin L. Sitze</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/escape/">escape</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/quote/">quote</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>This Python module quotes a Python string so that it will be treated as a single argument to commands ran via os.system() (assuming bash is the underlying shell). In other words, this module makes arbitrary strings "command line safe" (for bash command lines anyway, YMMV if you're using Windows or one of the (less fine) posix shells).</p> A utility like Unix seq (command-line), in Python (Python) 2017-01-08T17:48:57-08:00Vasudev Ram <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="" rel="nofollow"></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="" rel="nofollow"></a></p> <p>The code is below.</p> PyTube (Python) 2008-12-07T01:19:17-08:00Jonny Reeves <p style="color: grey"> Python recipe 576524 by <a href="/recipes/users/4167414/">Jonny Reeves</a> (<a href="/recipes/tags/internet/">internet</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/search/">search</a>, <a href="/recipes/tags/youtube/">youtube</a>). Revision 3. </p> <p>Based off PyGoogle, this script searches Youtube. </p> Gimp Paperwhite Scriptfu (Python) 2014-03-25T10:17:07-07:00Alfe <p style="color: grey"> Python recipe 578857 by <a href="/recipes/users/4182236/">Alfe</a> (<a href="/recipes/tags/gimp/">gimp</a>, <a href="/recipes/tags/image_processing/">image_processing</a>, <a href="/recipes/tags/paperwhite/">paperwhite</a>, <a href="/recipes/tags/plugin/">plugin</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/scriptfu/">scriptfu</a>). </p> <p>This Gimp-plugin (written in Python) changes a photograph of a paper document so that the paper background appears white again without overly lighting the text.</p> Heise mp3 downloader (Python) 2009-01-17T11:51:39-08:00d.schlabing <p style="color: grey"> Python recipe 576618 by <a href="/recipes/users/4168903/">d.schlabing</a> (<a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/threads/">threads</a>). </p> <p>This little script presents new heise-news-articles individually by title and asks if it should download the corresponding mp3-file.</p> ZipScript: Build a directly executable zipped Python script set (Python) 2010-02-11T15:32:38-08:00Glenn <p style="color: grey"> Python recipe 577042 by <a href="/recipes/users/4171639/">Glenn</a> (<a href="/recipes/tags/package/">package</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/zip/">zip</a>). Revision 2. </p> <p>This function will package a python script and additional python modules, in either source or compiled form. Either are directly executable by Python 2.7/3.1 or newer.</p> <p>Uses make-like logic to only rebuild if something is newer than the previous build.</p> A Building Block, Bash Binary File Manipulation... (Bash) 2013-01-29T22:07:57-08:00Barry Walker <p style="color: grey"> Bash recipe 578441 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>). Revision 2. </p> <p>Apologies for any typos, and IF this has been done before...</p> <p>The code generates a 256 byte binary file of _characters_ 0x00 to 0xFF for general usage and generates another binary file manipulated in a basic way.</p> <p>The for loops in the code are purely for DEMO purposes only.</p> <p>This is Public Domain and you may do with it as you please. I have uploaded it elsewhere too...</p> <p>Watch for wordwrapping, etc and read the code for more information...</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> <p>Bazza, G0LCU...</p> A Script that Adds a Directory to sys.path Permanently (Python) 2012-02-16T23:15:11-08:00Eric Snow <p style="color: grey"> Python recipe 578043 by <a href="/recipes/users/4177816/">Eric Snow</a> (<a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/sys_path/">sys_path</a>). </p> <p>This script takes advantage of PEP 370, "Per user site-packages directory". It manages .pth files, which are are non-volatile (unlike manually adding to sys.path). See <a href="" rel="nofollow"></a></p> (gopytranslte) script google translator (Python) 2011-04-14T17:17:12-07:00namakukingkong <p style="color: grey"> Python recipe 577556 by <a href="/recipes/users/4176734/">namakukingkong</a> (<a href="/recipes/tags/api/">api</a>, <a href="/recipes/tags/google/">google</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/translate/">translate</a>, <a href="/recipes/tags/translator/">translator</a>). Revision 3. </p> <p>hehehehe..... Very little code for study.....</p> A simple shell script to keep the wife off of your back... (Bash) 2013-12-09T20:05:49-08:00Barry Walker <p style="color: grey"> Bash recipe 578781 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/apple/">apple</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/macbook_pro/">macbook_pro</a>, <a href="/recipes/tags/reminder/">reminder</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>How many times have you been asked to remember to do something from the other half whilst she is out for a short while.</p> <p>For example: "You WILL check the dinner every few minutes won't you?"</p> <p>And how many times did/do you forget?</p> <p>Most of us have been there...</p> <p>This is a simple kids level, practical learning, shell script that generates an "xterm" with your reminder inside every 30 seconds for a period of 3 seconds.</p> <p>It is always be the active front window for 3 seconds at a time to _annoy_ you into remembering.</p> <p>Usage: reminder "What you have to remember here using spaces AND double quotes."&lt;CR&gt;</p> <p>Just reanme the downloaded script to reminder and remember to chmod it as required.</p> <p>Just run it from your default terminal and when finished press Ctrl-C just AFTER the xterm window closes.</p> <p>There is NO error detection so steer clear of any special characters in you reminder text.</p> <p>Enjoy finding simple solutions to often very difficult problems...</p> Bash Script For An Oscilloscope... (Bash) 2013-06-19T19:06:50-07:00Barry Walker <p style="color: grey"> Bash recipe 578570 by <a href="/recipes/users/4177147/">Barry Walker</a> (<a href="/recipes/tags/anim/">anim</a>, <a href="/recipes/tags/audio/">audio</a>, <a href="/recipes/tags/audioscope/">audioscope</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/oscilloscope/">oscilloscope</a>, <a href="/recipes/tags/scope/">scope</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/sound_exchange/">sound_exchange</a>, <a href="/recipes/tags/sox/">sox</a>, <a href="/recipes/tags/terminal/">terminal</a>). </p> <p>This code is the latest as of 19-06-2013. It is an AudioScope designed around a Macbook Pro 13" of which only has ONE microphone input. It works under Linux variants too. Read the code for much more info.</p> <p>It was my way of learning Bash scripting.</p> <p>It is resident here at this site:-</p> <p><a href="" rel="nofollow"></a></p> <p>It started off as a fun idea and is now becoming a very serious project.</p> <p>As it stands this is fully working but it is uncalibrated and this is where it will stay on this site.</p> <p>As the above site is the host then all future uploads will be there...</p> <p>To do list...</p> <p>DC input. [1] DC polarity. [1] 2 more Internal sync modes. External triggering. Zoom facility - if possible in text mode. Vertical calibration. [2] Frequency measurement. {3] (Others.)</p> <p>[1] I have simple HW built as an idea but yet to prove it... [2] Preliminary HW built but not yet used. Calibration SW and circuit(s) to be built into script as it progresses. [3] I already have a working script but not completely satisfied at it at this point...</p> <p>I am noing to say much else except that it has already been given a 5 star rating on the above UNIX site...</p> <p>As it stands this code is entirely Public Domian and you may do with it as you please...</p> <p>Enjoy something completely different using Bash scripting...</p> <p>Finally the code defaults to a DEMO mode which requires no HW access at all but everything is still functional...</p> <p>__Thoroughly__ read the code for more information...</p> <p>As a circuit is inside the script then it is best viewed in plan text mode.</p> <p>Bazza, G0LCU.</p> Bash completed man and info pages generation (Python) 2011-08-24T03:14:13-07:00Josh D <p style="color: grey"> Python recipe 577854 by <a href="/recipes/users/4179060/">Josh D</a> (<a href="/recipes/tags/a/">a</a>, <a href="/recipes/tags/all/">all</a>, <a href="/recipes/tags/and/">and</a>, <a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/be/">be</a>, <a href="/recipes/tags/command/">command</a>, <a href="/recipes/tags/completed/">completed</a>, <a href="/recipes/tags/consume/">consume</a>, <a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/first/">first</a>, <a href="/recipes/tags/generation/">generation</a>, <a href="/recipes/tags/get/">get</a>, <a href="/recipes/tags/in/">in</a>, <a href="/recipes/tags/info/">info</a>, <a href="/recipes/tags/line/">line</a>, <a href="/recipes/tags/man/">man</a>, <a href="/recipes/tags/modify/">modify</a>, <a href="/recipes/tags/must/">must</a>, <a href="/recipes/tags/only/">only</a>, <a href="/recipes/tags/pages/">pages</a>, <a href="/recipes/tags/possibilties/">possibilties</a>, <a href="/recipes/tags/possiblities/">possiblities</a>, <a href="/recipes/tags/py/">py</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/run/">run</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/so/">so</a>, <a href="/recipes/tags/tab/">tab</a>, <a href="/recipes/tags/terminal/">terminal</a>, <a href="/recipes/tags/the/">the</a>, <a href="/recipes/tags/this/">this</a>, <a href="/recipes/tags/to/">to</a>). Revision 6. </p> <p>The script it self is very self explaining - the task is simple. *NIX only unless with cygwin perhaps?</p> <p>To start this open a terminal and strike the "Tab" key to get all possibilities (strike y, and strike the space key alot). Select all then Copy and save in "comms.txt" Modify the file so ONLY the possiblities consume a line; no prompts or extra newlines. (first line must be a command, the last line must be a command)</p> <p>Save the file ("~/Documents/bashing/comms.txt" is my path) then run this script in "~/Documents/bashing/".</p> <p>This generates two (2) files: "", "".</p> <p>Then it runs these files: "bash", "bash".</p> <p>This produces 2 files for every command (every line) in "comms.txt". All manpages are wrote in "mans/", all infopages are wrote in "infos/"</p> <p>There is now alot of files to read and organize; lets separate these by size. Directories are under1kb, under2kb, etc.</p> <p>Once complete do as you wish the files less than 128 kb; these files are COPIED into there new respective home, I repeat COPIED.</p> <p>The files 128 kb and higher ARE NOT copied to anywhere!</p> Pass The FizzBuzz Test (Bash) 2011-11-02T00:26:45-07:00userend <p style="color: grey"> Bash recipe 577938 by <a href="/recipes/users/4179007/">userend</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/buzz/">buzz</a>, <a href="/recipes/tags/fizz/">fizz</a>, <a href="/recipes/tags/fizzbuzz/">fizzbuzz</a>, <a href="/recipes/tags/job/">job</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>). </p> <p>This is my version of the FizzBuzz test.</p> A script to automate installing MTS Mblaze UI in linux (Bash) 2015-07-29T18:26:59-07:00Emil george james <p style="color: grey"> Bash recipe 579039 by <a href="/recipes/users/4191910/">Emil george james</a> (<a href="/recipes/tags/internet/">internet</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/web/">web</a>). </p> <p>An automate shell linux script to install mts mblaze ui application in all linux distros.this shell script automatically install the mts mblaze ui in your linux systems .installation script will setup everything need to choose some option interactively from setup.Script can work for all linux environments.</p> A simple Unix shell utility to save cleaned-up man pages as text (Bash) 2017-03-25T14:12:25-07:00Vasudev Ram <p style="color: grey"> Bash recipe 580766 by <a href="/recipes/users/4173351/">Vasudev Ram</a> (<a href="/recipes/tags/bash/">bash</a>, <a href="/recipes/tags/documentation/">documentation</a>, <a href="/recipes/tags/man/">man</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/shell/">shell</a>, <a href="/recipes/tags/utilities/">utilities</a>, <a href="/recipes/tags/utility/">utility</a>). </p> <p>It's a shell script that lets you save the man pages for one or more Unix commands, system calls or other topics, to text files, after cleaning up the man command output to remove formatting meant for emphasis, printing, etc.</p> <p>More information here:</p> <p><a href="" rel="nofollow"></a></p> Clear Only Project Modules (Python) 2014-12-17T19:03:15-08:00Cornelius Jatniel Prinsloo <p style="color: grey"> Python recipe 578982 by <a href="/recipes/users/4191358/">Cornelius Jatniel Prinsloo</a> (<a href="/recipes/tags/clear/">clear</a>, <a href="/recipes/tags/modules/">modules</a>, <a href="/recipes/tags/project/">project</a>, <a href="/recipes/tags/reload/">reload</a>, <a href="/recipes/tags/script/">script</a>, <a href="/recipes/tags/startup/">startup</a>). </p> <p>Useful for python sessions that have a long startup time because of external dependancies [In my case that would be pygame and pymunk] I've got a slow computer so it takes a while to startup this is the solution I came up with</p> <p>import this before any other of your project imports example: import reloading # The modules in your project folder get cleared then load the rest of your project modules</p> <p>make sure that the reloading script is in your project folder, or else it won't work</p> <p>You might be able to extend this by changing line</p>