better bash debugging

2011-09-16 1 min read Bash Linux

I was trying to debug some bash scripts yesterday and learnt something new ๐Ÿ˜‰
There are lot of things in bash that you can use to debug and to start with you can enable xtrace mode as follows:

set -x

With this set you will see that all the commands are printed along with all other information as they are executed.
This you can do for any line or for the function or for the whole script. Once you set the option you can turn it
off with

Continue reading

ss โ€“ utility to investigate sockets.

2011-09-07 1 min read Fedora Linux

Sometimes, you find some interesting application/command by accident, and that is just what happened a few days back. Well, I was doing a ssh and as usual made my share of mistake in typing and missed the โ€œhโ€ from the ssh command and saw a list of options instead of my prompt on remote server.

Now, that set me thinking and fond that its a very interesting command that comes with iproute on Fedoara, so if you want this command, then install iproute like this

Continue reading

[Solved] ssh works but scp does not

2011-08-29 1 min read Bash Fedora Linux

Structure of an SSH binary packet
Image via Wikipedia

For quite sometime now, I was having this issue, that for the home system, I was able to connect to is using ssh but it never worked. Fnally after quite some debugging finally I found that the issue was with thebashrc. So, everytime I had to do a scp I would have to move/rename bashrc and do the reverse action after the scp was done.

Continue reading

Screenshot of Gnome3 with awn

2011-08-25 1 min read Fedora GNOME Linux

Here is another screenshot of my laptop desktop with Gnome 3 and AWN (Avant window Navigator) running. Looks beautiful, isnโ€™t it?

<p>
  By the way, with this setup I have the <a class="zem_slink" title="Old Style and New Style dates" href="http://en.wikipedia.org/wiki/Old_Style_and_New_Style_dates" rel="wikipedia">old style</a> menu also just that instead of on the top it is on the bottom just like old RH9 ๐Ÿ™‚
</p>

<h6 class="zemanta-related-title" style="font-size: 1em;">
  Related articles
</h6>

<ul class="zemanta-article-ul">
  <li class="zemanta-article-ul-li">
    <a href="http://blog.amit-agarwal.co.in/2011/08/12/gnome-3-shell-themes/">Gnome 3 shell themes</a> (amit-agarwal.co.in)
  </li>
  <li class="zemanta-article-ul-li">
    <a href="http://tech.slashdot.org/story/11/08/17/1943218/Interview-With-GNOME-3-Designer-Jon-McCann">Interview With GNOME 3 Designer Jon McCann</a> (tech.slashdot.org)
  </li>
  <li class="zemanta-article-ul-li">
    <a href="http://linux.slashdot.org/story/11/08/04/0115232/Linus-Torvalds-Ditches-GNOME-3-For-Xfce">Linus Torvalds Ditches GNOME 3 For Xfce</a> (linux.slashdot.org)
  </li>
</ul>

<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;">
  <a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="float: right;" src="https://i1.wp.com/img.zemanta.com/zemified_e.png?w=688" alt="Enhanced by Zemanta" data-recalc-dims="1" /></a>
</div>

<p>
</p>

bash completion

2011-08-09 2 min read Bash Fedora Linux

I was working on some functions in bash to make my life easier and realized that if I added custom completion to my functions, it will be really good. So I headed over to google and searched for what I wanted. I did get a lot of information on bash completion but not a single concrete example that could help me do what I wanted. So, with the help of man pages and some results from the Google pages, I was finally able to accomplish what I wanted. So here it is:

Continue reading

faster bash operations on files with File Descriptors.

2011-06-11 2 min read Bash Learning Linux

I was writing a bash script that would do some operations and read and write to file. Seems that that was pretty simple with

  <td>
    <div class="text codecolorer">
      while read line<br /> <br /> do<br /> <br /> done<file
    </div>
  </td>
</tr>
1
2
3
4
5

and then use redirection operations like โ€œ>โ€ and โ€œ»โ€ to write to file. Done with the script pretty fast. So far so good, when I went for real life tests, no one was interested in using it, why? Simple, it was simply taking too long. The file was reading about 10K lines and writing about 50 lines and was taking about more than 10 minutes.

Continue reading

Unix shell script for removing duplicate files

2011-05-16 1 min read Bash Linux

The following shell script finds duplicate (2 or more identical) files and outputs a new shell script containing commented-out rm statements for deleting them (copy-paste from here):

::: updated on 02 May 20121, seems like wordpress did not like it so well so reformatting the code :::::::

#!/bin/bash -
#===============================================================================
#
#          FILE:  a.sh
#
#         USAGE:  ./a.sh
#
#   DESCRIPTION:
#
#       OPTIONS:  ---
#  REQUIREMENTS:  ---
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR: Amit Agarwal (aka), amit.agarwal@roamware.com
#       COMPANY: blog.amit-agarwal.co.in
#       CREATED: 02/05/12 06:52:08 IST
# Last modified: Wed May 02, 2012  07:03AM
#      REVISION:  ---
#===============================================================================

OUTF=rem-duplicates.sh;
echo "#!/bin/sh" >$OUTF;
find "$@" -type f -exec md5sum {} \; 2>/dev/null | sort --key=1,32 | uniq -w 32 -d |cut -b 1-32 --complement |sed 's/^/rm -f/' >>$OUTF

Pretty good one line, I must say ๐Ÿ™‚

Continue reading
Older posts Newer posts