change the output format for time command

2016-08-16 1 min read bash
If you are doing some scripting and using ‘time’ command, then you know sometimes it becomes difficult to capture the output as the output would be something like this: : amit ; time ls real 0m0.002s user 0m0.000s sys 0m0.001s So, it is better to change that format. Here is simple example: 1 <td> <div class="text codecolorer"> &nbsp; </div> </td> </tr> TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls amit ; TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls 0. Continue reading

Home grown mail scheduler with bash script and cron

2013-10-04 2 min read bash Linux
If you are using Linux (Fedora/Ubuntu or anything else) then you do get a lot of tools and one of them is cron. Very very useful. Just write some script that can do the task for you, put it in cron and forget it. So, here is a home grown way to schedule mails. First, copy this script below: #!/bin/bash - #=============================================================================== # # FILE: sched_mail.sh # # USAGE: ./sched_mail.sh # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Amit Agarwal (aka), # REVISION: --- #=============================================================================== mailfile=" 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. Continue reading

convert tabs to spaces, the easy way

2013-07-08 1 min read bash Fedora
Lots of times you want to convert tabs to spaces and sometimes from a shell script, if that is the case, then simple solution is “tidy“. First you need to install tidy as follows: sudo yum install tidy and then you can use the command tab2space. tab2spcae This will print the output to STDOUT by default which you can redirect if you want. Related articles All You Wanted To Know About HERE Documents in Linux

quick bash script for datewise backup of directory

2012-12-12 1 min read bash Linux
I was working on something and the data was very critical and needed backup. I wrote a bash script to back up the data every 5 hours with cron and bash script. Thought I will share that with you. Here is the script. #!/bin/bash - #=============================================================================== # # FILE: backup.sh # # USAGE: ./backup.sh # # DESCRIPTION: Backup all the current files. # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: Amit Agarwal (aka), amit. Continue reading
Older posts