coproc help - a new feature in bash

2010-05-10 0 min read Bash Fedora Linux
\"Screenshot
Image via Wikipedia

In the <a class="zem_slink freebase/en/bash" title="Bash" rel="homepage" href="http://tiswww.case.edu/php/chet/bash/bashtop.html">bash version 4.0, there is a new concept called coproc. This is very useful for some of the daily tasks.

co-<a class="zem_slink freebase/guid/9202a8c04000641f800000000005a409" title="Process (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Process_%28computing%29">process starts a process in the background, optionally with a NAME, with which other processes can communicate. This can be a very <a class="zem_slink freebase/en/substitute_good" title="Substitute good" rel="wikipedia" href="http://en.wikipedia.org/wiki/Substitute_good">good substitution for <a class="zem_slink freebase/guid/9202a8c04000641f800000000048fac5" title="Pipeline (Unix)" rel="wikipedia" href="http://en.wikipedia.org/wiki/Pipeline_%28Unix%29">pipes in lots of cases. You can learn more about coproc in the link below:

Continue reading

Download with browse with bash and wget

2010-05-09 1 min read Bash Fedora

Been pretty busy for last couple of days. Will be busy for another few days, but here&#8217;s something to munch in the meantime (Script may need changes depending on the type of file you want to download or the site you are browsing, but the chnages should be minimal):

file=&#8221;/tmp/temp.dir&#8221;
url=&#8221;URL Here&#8221;
IFS=&#8217;
&#8217;
cont=&#8221;y&#8221;
while [ $cont != &#8221;n&#8221; ]
do
name=&#8221;&#8221;
wget &#8221;$url&#8221; -O $file -o /dev/null
for i in $(grep href $file |grep -v Parent)
do
name=${i##href=&#8221;}
name=${name%%&#8221;>
}
echo $name
if [[ $name == *gz ]]
then
cont=&#8221;n&#8221;
fi
done
if [ ! $name ]
then
echo &#8221;No files here.. Exiting&#8221;
exit -1
fi
echo
if [ $cont == &#8221;n&#8221; ]
then
echo &#8221;Enter the filename for download :&#8221;
read file
fi
echo &#8221;Select one of the options:&#8221;
read product
url=&#8221;$url/$product&#8221;
echo &#8221;About to get $url&#8221;
done
wget &#8221;$url&#8221; -O $file -o /dev/null

Continue reading

bash script to periodically change the cursor theme.

2010-05-07 1 min read Fedora GNOME

#!/bin/bash
[[ &#8221;$1&#8221; == &#8221;&#8221; ]] && time=5 || time=$1
[[ &#8221;$2&#8221; == &#8221;&#8221; ]] && (
cd ~/.icons
cont=&#8221;y&#8221;
echo &#8221;Select one of the icon themes&#8221;
echo &#8221;When you like some theme just press Ctrl+c&#8221;
for i in *
do
[[ -d $i/cursors ]] && (
echo &#8221;Now trying …. : $i&#8221;
gconftool-2 –type string -s  /desktop/gnome/peripherals/mouse/cursor_theme &#8221;$i&#8221;
sleep $time
)
done
) || gconftool-2 –type string -s  /desktop/gnome/peripherals/mouse/cursor_theme &#8221;$2&#8221;

Continue reading

xterm – select font name and size from command line and set it as default

2010-05-05 2 min read Fedora Linux

I have been very busy last week and specially yesterday with 20 hours of continueous work, but managed to get this working :).

When you right click on Xterm with Ctrl pressed, there pops up a menu for selecting the size of the font. I have always wondered how to set this as default font and/or use this from the command line. So I searched my old homedir and looked for few of the docs that I had to get the information. Here is what I found.

Continue reading

Quick notepad in bash without any editor

2010-04-12 1 min read Bash

$ «.>note Bash internal quick note taker, avoiding calling external programs like cat

  • <a href="http://www.commandlinefu.com/commands/view/3939/quick-notepad">View this command to comment, vote or add to favourites
  • <a href="http://feeds2.feedburner.com/commands/by/netizen">View all commands by <a href="http://feeds2.feedburner.com/commands/by/netizen">netizen

<a href="http://www.commandlinefu.com"><img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/header-logo.jpg" alt="" align="bottom" />

by David Winterbottom (<a href="http://codeinthehole.com">codeinthehole.com)

<a href="http://feedads.g.doubleclick.net/~a/aAyNWJ1rcV4brCukeWT51QSbCZs/0/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/aAyNWJ1rcV4brCukeWT51QSbCZs/0/di" alt="" align="bottom" />
<a href="http://feedads.g.doubleclick.net/~a/aAyNWJ1rcV4brCukeWT51QSbCZs/1/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/aAyNWJ1rcV4brCukeWT51QSbCZs/1/di" alt="" align="bottom" />

<img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~r/Command-line-fu/~4/luL4fGyQxqk" alt="" width="1" height="1" align="bottom" />

URL: <a href="http://feedproxy.google.com/~r/Command-line-fu/~3/luL4fGyQxqk/quick-notepad">http://feedproxy.google.com/~r/Command-line-fu/~3/luL4fGyQxqk/quick-notepad

Linux Shell Scripting Tutorial – A Beginner\’s handbook

2010-04-11 0 min read Bash Learning Linux
\"Tux,
Image via Wikipedia

<a class="zem_slink freebase/en/unix_shell" title="Unix shell" rel="wikipedia" href="http://en.wikipedia.org/wiki/Unix_shell">Linux Shell Scripting Tutorial – A Beginner&#8217;s handbook —

This book is for students and Linux System Administrators. It provides the skills to read, write, and debug <a title="Linux" href="http://bash.cyberciti.biz/guide/Linux">Linux <a class="zem_slink freebase/en/shell_script" title="Shell script" rel="wikipedia" href="http://en.wikipedia.org/wiki/Shell_script">shell scripts using <a title="Bash" href="http://bash.cyberciti.biz/guide/Bash">bash <a title="Shell" href="http://bash.cyberciti.biz/guide/Shell">shell. The book begins by describing <a title="Linux" href="http://bash.cyberciti.biz/guide/Linux">Linux and simple scripts to automate frequently executed commands and continues by describing conditional logic, <a class="zem_slink freebase/en/interactivity" title="Interactivity" rel="wikipedia" href="http://en.wikipedia.org/wiki/Interactivity">user interaction, loops, menus, traps, and functions. Finally, book covers various sys admin related scripts such as making a backup, using <a class="zem_slink freebase/guid/9202a8c04000641f80000000045c9c5b" title="Cron" rel="wikipedia" href="http://en.wikipedia.org/wiki/Cron">cron jobs, writing interactive tools, web based tools, remote login, ftp and database backup related scripts. This book is intended for Linux <a class="zem_slink freebase/en/system_administrator" title="System administrator" rel="wikipedia" href="http://en.wikipedia.org/wiki/System_administrator">system administrators or students who have mastered the basics of a Linux Operating System. You should be able to:

Continue reading

Jokes – many to be downloaded once..

2010-04-11 1 min read Bash Fedora Linux

All work and no fun makes Jack dull boy. So lets do something for fun. Here is a one liner I wrote sometime back.  The original idea is not mine and I don&#8217;t remeber where I got the idea from but it was some other one liner that I was browsing for some oracle query. Anyway here&#8217;s the one liner to get lot of jokes in one file.

#!/bin/bash
for i in `echo 000{0..9} 00{10..99} 0{100..999} {1000..1600}` ; do links -dump http://www.robsjokes.com/$i/index.html | sed &#8217;/Random Joke/,/Next Joke/!d&#8217; | sed &#8217;/^$/,/^$/!d&#8217; » ~/Rob.jokes ; echo &#8217;%&#8217; » ~/Rob.jokes ;echo $i; done

Continue reading
Older posts Newer posts