script to get hard disk health in fedora/ubuntu

2014-12-01 1 min read Fedora Learning Linux
First, put this in a script. #!/bin/bash #Change as appropriate HDD=sda export sub="SmartCtl data for HDD" echo 'To: <Your Email> Sub: [Cron] $sub MIME-Version: 1.0 Content-Type: text/html Content-Disposition: inline <html><pre>' echo '<style> hr { display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0; } </style> ' echo '<h2>Errors on HDD:</h2>' echo '<hr>' sudo smartctl -l error /dev/$HDD echo '<h2>Health of HDD:</h2>' echo '<hr>' sudo smartctl -H /dev/$HDD echo '<h2>Detailed info</h2>' echo '<hr>' sudo smartctl -a -d ata /dev/$HDD echo '<h2>Journalctl output for smartd</h2>' echo '<hr>' if [[ -f /etc/fedora-release ]] then journalctl -x --show-cursor -u smartd --since=yesterday else #This is for Ubuntu. Continue reading

Debuggging bash cron scripts.

2014-09-01 1 min read bash Learning
I have to several times debug scripts that I get complain about working when logging in normally but they do not work when run in cron mode. So, quite a lot of times, redirecting the stderr of the script is all that is required to see what is happening, but sometimes that just does not help if the script is calling another script which is mis-behaving and under lot of other conditions. 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. Continue reading

shopt causes bash completion to stop working.

2011-01-25 1 min read bash
Couple of days, I added some scripts to my bash startup and suddenly realized that bash completions stopped working. This is tricky situation in bash to figure out what went wrong. So, I set my foot down to make sure that I find out the culprit. Thus I started with method of elimination. So, I started with nothing in .bashrc and kept adding my stuff in batches, until the said feature was broken. Continue reading

bash 4.0 – new feature mapfile

2011-01-14 1 min read bash Fedora
Recently I encountered a problem where I had to create couple of arrays in bash and these were quite dynamic in nature. This script was supposed to be used by couple of guys whom I did not trust too much in opening the script and modifyikng the array. So, the solution was to put these in different files and then put them in array using bash script itself. This is when I went through the bash man page again and found an interesting new inbuilt mapfile Continue reading

perl is faster than bash in some cases.

2011-01-11 3 min read bash Fedora Linux perl
Some days back, I had to generate some data to be uploaded to a database. As usual I assumed that bash should be faster and hence wrote the script to create the files in bash. But I found that even after 5 hours I was only 10% done with the data generation. Now that would mean that it would take around 50 hours to complete the data generation. Something did not look correct to me and I asked one of my colleague. Continue reading
Older posts Newer posts