CLI Color and bash prompt.. some colored fun with prompts in bash

2010-06-29 5 min read Bash Fedora Linux

There are two ways to do it, one is with tput command. We will see that some other time, today we will consider the escape sequence way.

First we need to understand the colors as understood by bash. Some time back a fried of mine gave me this little script to find the colors. You can download it <a href="http://blog.amit-agarwal.co.in/2009/03/bash_colors" target="_blank">Script bash colors. Here is the script

#!/bin/bash

T=&#8217;amit agarwal&#8217;   # The test text

Continue reading

Getting your wordpress self hosted stats on your console with bash script.

2010-06-29 3 min read Bash Learning

Some time back I wrote a blog on how to get your site stats using curl in <a class="zem_slink freebase/en/bash" title="Bash" rel="homepage" href="http://tiswww.case.edu/php/chet/bash/bashtop.html">bash shell. Today we will use the same script to get the stats every few seconds on the terminal on the same line, similar to progress meter.

Here is the script and the description:

  <td>
    <div class="bash codecolorer">
      <span class="co0">#!/bin/bash -</span><br /> <span class="co0">#===============================================================================</span><br /> <span class="co0">#</span><br /> <span class="co0">#          FILE:  update_stats.sh</span><br /> <span class="co0">#</span><br /> <span class="co0">#         USAGE:  ./update_stats.sh</span><br /> <span class="co0">#</span><br /> <span class="co0">#   DESCRIPTION:  Update the stats inline in shell every $1 seconds.</span><br /> <span class="co0">#</span><br /> <span class="co0">#       OPTIONS:  ---</span><br /> <span class="co0">#  REQUIREMENTS:  ---</span><br /> <span class="co0">#          BUGS:  ---</span><br /> <span class="co0">#         NOTES:  ---</span><br /> <span class="co0">#        AUTHOR:  <a class="zem_slink" title="Amit Agarwal" rel="homepage" href="http://amit-agarwal.co.in">Amit Agarwal</a> (AKA), amit.agarwal@amit-agarwal.co.in</span><br /> <span class="co0">#       COMPANY:  Individual</span><br /> <span class="co0">#       VERSION:  1.0</span><br /> <span class="co0">#       CREATED:  06/21/2010 11:27:16 PM IST</span><br /> <span class="co0">#      REVISION:  ---</span><br /> <span class="co0">#===============================================================================</span><br /> <br /> <span class="re2">sleep_time</span>=<span class="nu0">30</span> <span class="co0">#the time to wait between stats collection</span><br /> <span class="re2">run_stats</span>=get_stats  <span class="co0"># the script to run to get the stats</span><br /> <span class="re2">filename</span>=<span class="sy0">/</span>tmp<span class="sy0">/</span>statpress.html <span class="co0"># the filename where the script is storing the html file of your statpress page.</span><br /> <span class="kw3">eval</span> <span class="re1">$run_stats</span> <span class="nu0">2</span><span class="sy0">><</span>a <span class="re2">class</span>=<span class="st0">"zem_slink freebase/en/dev_null"</span> <span class="re2">title</span>=<span class="st0">"/dev/null"</span> <span class="re2">rel</span>=<span class="st0">"wikipedia"</span> <span class="re2">href</span>=<span class="st0">"http://en.wikipedia.org/wiki//dev/null"</span><span class="sy0">>/</span>dev<span class="sy0">/</span>null<span class="sy0"></</span>a<span class="sy0">></span><br /> <span class="kw1">while</span> <span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span><br /> <span class="kw1">do</span><br /> <span class="sy0"><!</span>--loginview start--<span class="sy0">></span><span class="re2">values</span>=$<span class="br0">&#40;</span><span class="kw2">cat</span> <span class="re1">$filename</span> <span class="sy0">|</span> w3m <span class="re5">-dump</span> <span class="re5">-T</span> <span class="sy0"><</span>a <span class="re2">class</span>=<span class="st0">"zem_slink freebase/en/html"</span> <span class="re2">title</span>=<span class="st0">"HTML"</span> <span class="re2">rel</span>=<span class="st0">"wikipedia"</span> <span class="re2">href</span>=<span class="st0">"http://en.wikipedia.org/wiki/HTML"</span><span class="sy0">></span>text<span class="sy0">/</span>html<span class="sy0"></</span>a<span class="sy0">></span> <span class="sy0">|<</span>a <span class="re2">class</span>=<span class="st0">"zem_slink freebase/en/grep"</span> <span class="re2">title</span>=<span class="st0">"Grep"</span> <span class="re2">rel</span>=<span class="st0">"wikipedia"</span> <span class="re2">href</span>=<span class="st0">"http://en.wikipedia.org/wiki/Grep"</span><span class="sy0">></span><span class="kw2">grep</span><span class="sy0"></</span>a<span class="sy0">></span> <span class="st0">"^Visitor\\|^Pageviews"</span><span class="sy0">|<</span>a <span class="re2">class</span>=<span class="st0">"zem_slink freebase/en/awk"</span> <span class="re2">title</span>=<span class="st0">"AWK"</span> <span class="re2">rel</span>=<span class="st0">"homepage"</span> <span class="re2">href</span>=<span class="st0">"http://cm.bell-labs.com/cm/cs/awkbook/index.html"</span><span class="sy0">></span><span class="kw2">awk</span><span class="sy0"></</span>a<span class="sy0">></span> <span class="co3">\'</span><span class="br0">&#123;</span>print <span class="re4">$1</span><span class="nu0"></span><span class="br0">&#125;</span><span class="co3">\'</span><span class="sy0">|</span><span class="kw2">tr</span>  <span class="st0">"\<span class="es1">\n</span>"</span> <span class="st0">" "</span><span class="br0">&#41;</span><br /> <span class="re2">time</span>=$<span class="br0">&#40;</span><span class="kw2">date</span><span class="br0">&#41;</span><br /> <span class="kw3">printf</span> <span class="st0">"<span class="es2">$time</span> --> <span class="es2">$values</span> \<span class="es1">\r</span>"</span><span class="sy0"><!</span>--loginview end--<span class="sy0">></span><br /> <span class="kw2">sleep</span> <span class="re1">$sleep_time</span><br /> <span class="kw1">done</span>
    </div>
  </td>
</tr>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
\"Enhanced

Magic space on the current command line

2010-06-25 1 min read Bash Fedora Linux

# For how to set up magic space for Bash see:
# – http://www.ukuug.org/events/linux2003/papers/bash_tips/#slide15
# – http://codesnippets.joyent.com/posts/show/1690

man bash 2>/dev/null | less -p &#8217;magic-space&#8217;

man bash 2>/dev/null | less -p &#8217;Event Designators&#8217;

man bash 2>/dev/null | less -p &#8217;\!#&#8217; # &#8221;The entire <a class="zem_slink" title="Command-line interface" rel="wikipedia" href="http://en.wikipedia.org/wiki/Command-line_interface">command line typed so far.&#8221;

<a href="http://snippets.dzone.com/posts/show/10265">Read more :<h6 class="zemanta-related-title" style="font-size: 1em;">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="http://www.makeuseof.com/tag/trigger-wake-lan-mac-address/">How To Trigger Wake On LAN Using The MAC Address (makeuseof.com) <li class="zemanta-article-ul-li"><a href="http://smarterware.org/4271/projectview-lists-your-todo-txt-by-project">Projectview Lists Your Todo.txt by Project (smarterware.org) <li class="zemanta-article-ul-li"><a href="http://helpdeskgeek.com/linux-tips/shell-script-backup-directory-linux/">Back Up a Directory in Linux using a Shell Script (helpdeskgeek.com) <div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href="http://reblog.zemanta.com/zemified/038d79c3-59e6-41ad-a8ad-31d1af669509/"><img class="zemanta-pixie-img" style="border: medium none; float: right;" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/reblog_e39.png" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related pretty-attribution">

Continue reading

bash one liner to change/remove test pattern from config file or text file.

2010-06-25 1 min read Bash Fedora Learning Linux

Problem:

I had a directory with a lot of config files in the ini file format, i.e. name and value separated by equals. Some/all of these contained some directory names and other values which had to be replaced. But there were other place where I should not not replace them, if there was no exact match. I also needed to have a backup copy of the file that I was modifying. Since the number of files that I needed to change was multiple so was quite difficult to do it without using some script.

Continue reading

find duplicate entry in a list in bash with sed

2010-06-25 1 min read Bash Fedora Learning

Here I will take an example of rss2email list, but I guess I will be able to pass on the concept.

Here is example of the output of the r2e list command:

1: http://blog.amit-agarwal.co.in/feed (default: amitag@localhost)
2: http://feeds2.feedburner.com/AllAboutLinux (default: amitag@localhost)
3: http://feeds2.feedburner.com/Command-line-fu (default: amitag@localhost)
4: http://blogs.members.freewebs.com/Members/Blogs/viewBlogRSS.jsp?userid=29731143 (default: amitag@localhost)

Target here is to get the list of all duplicate entries if any. So, first we need to remove the numbers from the begining and the email ID from the end.

Continue reading

remove/replace text/path in config file.

2010-06-25 1 min read Bash

Lot of times I end up changing a particular text in config file to some other text. And when I have to do it for multiple files, all files having the text in multiple places, I end up opening the files in vim and then doing a globlal replace. But this is not efficient so I cam up with some one liners to do this for me. For removing any occurance of text in all files in the directory :

Continue reading
Older posts Newer posts