<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: bash code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Mon, 12 May 2008 08:31:36 GMT</pubDate>
    <description>DZone Snippets: bash code</description>
    <item>
      <title>WWAN Dialer</title>
      <link>http://snippets.dzone.com/posts/show/5484</link>
      <description>This script dials the built-in Verizon WWAN (mobile broadband) modem on my Thinkpad T61.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;#&lt;br /&gt;# Dial the WWAN&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;hang_up () {&lt;br /&gt;    echo &lt;br /&gt;    echo 'WWAN deactivated'&lt;br /&gt;    echo&lt;br /&gt;    exit&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;trap "hang_up" 2&lt;br /&gt;&lt;br /&gt;echo 'Activating WWAN'&lt;br /&gt;sudo modprobe -r airprime usbserial&lt;br /&gt;sudo modprobe usbserial vendor=0x1199 product=0x0220&lt;br /&gt;sudo modprobe airprime&lt;br /&gt;sleep 0.5&lt;br /&gt;sudo wvdial&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 11 May 2008 18:21:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5484</guid>
      <author>jmcvetta (Jason McVetta)</author>
    </item>
    <item>
      <title>Howto resize multiple pictures, graphics, images</title>
      <link>http://snippets.dzone.com/posts/show/5440</link>
      <description>&lt;code&gt;&lt;br /&gt;for k in $(ls *.jpg); do convert -resize 800 -quality 80 $k r800-$k; done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 29 Apr 2008 16:41:33 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5440</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
    <item>
      <title>Bash title random Quote routine</title>
      <link>http://snippets.dzone.com/posts/show/5428</link>
      <description>#&lt;br /&gt;#this is a script in my .bash_profile that gets a random&lt;br /&gt;#quote .txt file and assigns it to the terminal title.&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;quote_path="/Users/glynch/Documents/quotes/*"&lt;br /&gt;files=($quote_path)&lt;br /&gt;N=${#files[@]}&lt;br /&gt;((N=RANDOM%N))&lt;br /&gt;randomfile=${files[$N]}&lt;br /&gt;quote=""&lt;br /&gt;while read line; do quote="$quote $line"; done &lt; $randomfile&lt;br /&gt;echo -n -e "\033]0;$quote\007"</description>
      <pubDate>Thu, 24 Apr 2008 19:43:08 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5428</guid>
      <author>robotsu (Gavin)</author>
    </item>
    <item>
      <title>One-line web server in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/5424</link>
      <description>&lt;code&gt;&lt;br /&gt;&lt;br /&gt;# From: http://www.ntecs.de/blog/articles/2008/02/09/the-worlds-smallest-webserver&lt;br /&gt;# Author: Michael Neumann&lt;br /&gt;# ... point your browser to http://localhost:3125/etc/motd&lt;br /&gt;&lt;br /&gt;ruby -rsocket -e 's=TCPServer.new(5**5);loop{_=s.accept;_&lt;&lt;"HTTP/1.0 200 OK\r\n\r\n#{File.read(_.gets.split[1])rescue nil}";_.close}'&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 23 Apr 2008 13:22:36 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5424</guid>
      <author>ntk ()</author>
    </item>
    <item>
      <title>Sort last 1000 shell commands by popularity</title>
      <link>http://snippets.dzone.com/posts/show/5421</link>
      <description>&lt;code&gt;&lt;br /&gt;  history 1000 | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 22 Apr 2008 04:16:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5421</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Bashy Perlness for generating Favicon text for OpenSearches</title>
      <link>http://snippets.dzone.com/posts/show/5418</link>
      <description>&lt;code&gt;&lt;br /&gt;echo -n '&lt;Image width="16" height="16"&gt;data:image/xicon,' ; perl -ne 's/(.)/"%".unpack("H2",$1)/egs; print' ~/Desktop/favicon.ico ; echo '&lt;/Image&gt;' &lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Mon, 21 Apr 2008 19:58:49 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5418</guid>
      <author>sikelianos (Zeke Sikelianos)</author>
    </item>
    <item>
      <title>Changing the Bash prompt</title>
      <link>http://snippets.dzone.com/posts/show/5349</link>
      <description>The following shell command changes the bash prompt from this "james@cryton:~/projects/pear_housekeeping2/housekeeping$" to this "james@cryton&gt; "&lt;br /&gt;&lt;code&gt;&lt;br /&gt;export PS1="\n\u@\H&gt;"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;I tried the above example on Ubuntu 7.10.&lt;br /&gt;&lt;br /&gt;Reference:&lt;br /&gt;&lt;a href="http://www.ibm.com/developerworks/linux/library/l-tip-prompt/"&gt;Tip: Prompt magic&lt;/a&gt; [ibm.com]&lt;br /&gt;&lt;a href="http://tldp.org/HOWTO/Bash-Prompt-HOWTO/"&gt;Bash Prompt HOWTO&lt;/a&gt; [tldp.org]</description>
      <pubDate>Fri, 11 Apr 2008 22:43:21 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5349</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Batch re-size a collection of images from the command line</title>
      <link>http://snippets.dzone.com/posts/show/5298</link>
      <description>&lt;code&gt;&lt;br /&gt;for img in $(ls *.png); do convert $img -resize 75% smaller-$img; done;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 01 Apr 2008 09:33:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5298</guid>
      <author>27stars (27stars)</author>
    </item>
    <item>
      <title>Block many users in a system v0.1.1</title>
      <link>http://snippets.dzone.com/posts/show/5191</link>
      <description>Block many users in a system using a text file as argument&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;&lt;br /&gt;#******************************************************************************#&lt;br /&gt;# BlockManyUsers.sh - Block many users in a system using a text file           #&lt;br /&gt;#                       as argument                                            #&lt;br /&gt;#   Copyright (C) 2008 - written by flynets - &lt;flynets&lt;at&gt;autistici&lt;dot&gt;org&gt;   #&lt;br /&gt;#   BlockManyUsers is free software: you can redistribute it and/or modify     #&lt;br /&gt;#   it under the terms of the GNU General Public License as published by       #&lt;br /&gt;#   the Free Software Foundation, either version 3 of the License, or          #&lt;br /&gt;#   any later version.                                                         #&lt;br /&gt;#                                                                              #&lt;br /&gt;#   BlockManyUsers is distributed in the hope that it will be useful,          #&lt;br /&gt;#   but WITHOUT ANY WARRANTY; without even the implied warranty of             #&lt;br /&gt;#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               #&lt;br /&gt;#   GNU General Public License for more details.                               #&lt;br /&gt;#                                                                              #&lt;br /&gt;#   You should have received a copy of the GNU General Public License          #&lt;br /&gt;#   along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.      #&lt;br /&gt;#******************************************************************************#&lt;br /&gt;&lt;br /&gt;# Checks if you have the right privileges&lt;br /&gt;if [ "$USER" = "root" ];then&lt;br /&gt;   # Checks if there is an argument&lt;br /&gt;   [ $# -eq 0 ] &amp;&amp; { echo &gt;&amp;2 ERROR: You may enter as an argument a text file containing users, one per line. ; exit 1; }&lt;br /&gt;   # checks if there a regular file&lt;br /&gt;   [ -f "$1" ] || { echo &gt;&amp;2 ERROR: The input file does not exists. ; exit 1; }&lt;br /&gt;   TMPIN=$(mktemp)&lt;br /&gt;   # Remove blank lines and delete duplicates&lt;br /&gt;   sed '/^$/d' "$1"| sort -g | uniq &gt; "$TMPIN"&lt;br /&gt;   &lt;br /&gt;   NOW=$(date +"%Y-%m-%d-%X")&lt;br /&gt;   LOGFILE="BMU-log-$NOW.log"&lt;br /&gt;&lt;br /&gt;   for user in $(more "$TMPIN"); do&lt;br /&gt;      # Checks if the user already exists.&lt;br /&gt;      cut -d: -f1 /etc/passwd | grep "$user" &gt; /dev/null&lt;br /&gt;      OUT=$?&lt;br /&gt;      if [ $OUT -eq 0 ];then&lt;br /&gt;         # block selected user&lt;br /&gt;         /usr/sbin/usermod -L "$user"&lt;br /&gt;         # save user info in a file&lt;br /&gt;         echo The user \"$user\" has been blocked. &gt;&gt; "$LOGFILE"&lt;br /&gt;      else&lt;br /&gt;        echo &gt;&amp;2 Error the user account \"$user\" doesnt exists! &gt;&gt; "$LOGFILE"&lt;br /&gt;      fi&lt;br /&gt;   done&lt;br /&gt;   rm -f $TMPIN&lt;br /&gt;   exit 0&lt;br /&gt;else&lt;br /&gt;   echo &gt;&amp;2 ERROR: You must be a root user to execute this script.&lt;br /&gt;   exit 1&lt;br /&gt;fi&lt;br /&gt;exit 0&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 02 Mar 2008 14:23:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5191</guid>
      <author>flynets (Flynets is an italian student of computer science with passion for GNU/Linux and hacktivism.)</author>
    </item>
    <item>
      <title>Convert files to avi</title>
      <link>http://snippets.dzone.com/posts/show/5187</link>
      <description>Bash one-liner that converts all *.flvs in the current directory to .avis.&lt;br /&gt;&lt;br /&gt;Note: To convert something else, just change the .flv extension.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;for i in *.flv; do mencoder -ovc lavc -oac mp3lame -o "$i.avi" "$i"; done&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 29 Feb 2008 12:58:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5187</guid>
      <author>scvalex (Alexandru Scvortov)</author>
    </item>
  </channel>
</rss>
