Find directory/file with inode number

2013-09-10 1 min read Fedora Linux

Couple of days back, I was getting the following error:

Directory inode 2362521 has an unallocated block #245823.  Allocate?

And this continued for hours together and I was in a hurry. Did not really care about the error and all I wanted was to get rid of the error but for that I needed to get to the file/directory with inode number  mentioned in the error and finally “find” command came to rescue:

Continue reading

Set some disk params to be safe

2013-09-05 3 min read Fedora Linux

It is always “Better safe than sorry” so, here are some things you
should do..

First check fstab, if you have partitions other than root then use UUID instead of device:

UUID=a8f13a0d-3f1f-42e4-b076-f44b4163306c /mnt/Backup     ext4 defaults,relatime 1 2

Then entries for all your mounts should be like above.
Points to note here :

Disk is mounted using the UUID and not with /dev/sdXX. This ensures
that even if your disk ids change, you will be able to mount them. To
get the partition UUID, you can execute :

Continue reading

Delete all but some directories

2013-08-16 1 min read Bash Fedora Linux

I think, like me, you would have faced a lot of situations, where you wanted to delete all the files or directories in a location, leaving only the required files/directories. So, I have a directory containing lots of files/directories and I want to delete most of them except some 5/10 of them, how to I do it.

I finally wrote a small script to do that. First save list of files that you do not want to delete in file called “listnames” and then execute the below script. This will give you the rm commands that you need to execute. If you want you can execute the rm command from the script, but to be able to review, I just have the commands echoed.

Continue reading

LibreOffice – Formulae Auditing

2013-05-30 1 min read Learning Linux

If you have a excel sheet with lot of formula’s and you are trying to audit them, then a simple solution is to press “ctrl+`” (i.e. control key with back tick). This will put the excel sheet in Formula auditing mode and hence all the cells will show the formula rather than the values which will make it easier to audit them. Hope that helps.

Enhanced by Zemanta

procmail filters – apply to received mails.

2013-05-24 1 min read Linux

If you already have some mail in your maildir and you have set procmail filters, then it is difficult to apply the procmail filter, right? Not so, you just need to go to the Inbox directory and then execute the command.

for i in *; do cat $i|procmail; rm -f "$i"; done

This will pass all of your e-mail through procmail again and then your filters will get applied. Mails will go to their appropriate directory and you will be one happy man, I hope.

Continue reading

Manage your servers the easy way with perl script over ssh with no remote client.

2013-05-06 8 min read Linux Perl

For a long time I have not posted any script. So, its not that I have not written anything new, but just that did not put them here in lack of time. So, here is one interesting one. The original idea came from one posted in one of the interesting blog here. But the problem with this one was that for every time, it ran in the cron, it would make multiple entries in the “last” output (about 10 or more with my modifications for differentiating between solaris and Linux). This is something which is not quite desirable. Hence I came up with this script which is based on html template and hence the output is also easier to manipulate. BTW, just the below script will not help, you would need to download the template files as well. In the list.txt file, you will have to put the usename, password and the server IP to monitor. The server could be any Linux or Solaris host.

Continue reading

cksum – compare for multiple files.

2013-04-30 1 min read Fedora Learning Linux

If you have to compare cksum for couple of files, the you know how cumbersome it is. So, I wrote a simple script, wherein you can create a file called cksums in the current directory and copy paste the result of  “**cksums ***”  into this file, and then run this script. Cool 🙂

#!/bin/bash -
#===============================================================================
#
#          FILE: checkcksums.sh
#
#         USAGE: ./checkcksums.sh
#
#   DESCRIPTION: Compare cksums of multiple files.
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (),
#  ORGANIZATION:
#       CREATED: 02/22/2013 09:12:17 PM IST
#      REVISION:  ---
#===============================================================================

file=cksums
while read line
do
    a=( $(echo $line) )
    if [[ -f ${a[2]} ]]
    then
        b=( $(cksum ${a[2]}) )
        if [[ $a == $b ]]
        then
            echo "Cksum for ${a[2]} = ${a[0]} matches"
        else
            echo "Failed ::Cksum for ${a[2]} = ${a[0]} matches"
        fi
    else
        echo "Failed :: file ${a[2]} does not exist"
    fi
done < $file
Enhanced by Zemanta
Older posts Newer posts