bash ansi codes to html for html reports from shell script

2017-02-20 1 min read Bash

How many times you have felt that there was some simple way to convert bash ansi escape sequences ( colors as well in terminal ) to html equivalent so that you can send the same as html report in email. Here is simple solution. One way is to use ccze if you are using this for logs – colorize your logs and for more generic solution.

 

dnf install python3-ansi2html.noarch

after this is installed, you can use something like this:

Continue reading

Trello – backup to your linux machine

2017-01-02 1 min read Bash

Just in case, you are looking for backing up your trello account boards, you can use the following bash script to do so:

 

#!/bin/bash -
#===============================================================================
#
#          FILE: backup-trello.sh
#
#         USAGE: ./backup-trello.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#  ORGANIZATION: Mobileum
# Last modified: Thu Dec 22, 2016  01:14PM
#       CREATED: 08/12/2016 09:41:08 AM IST
#      REVISION: $Revision: 1.0 $$
#===============================================================================

# Your backup directory
BDIR=/backup

# Your trello api token and key goes here :)
token=<>
key=<>


# IDs of the boards go here. This is easy to get, just go to your 
# board and check the last part of URL
BOARDS=( a b )


URL="https://trello.com/b/"
POST='&actions=all&actions_limit=1000&cards=all&lists=all&members=all&member_fields=all&checklists=all&fields=all'

for i in ${BOARDS[*]}
do
    /usr/bin/curl -H 'Accept-Encoding:gzip, deflate, br' -H 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' "$URL$i.json?&key=$key&token=$token$POST" > "$BDIR/$i.json.gz"
    # gzip -f "$BDIR/$i.json"
done

 

Continue reading

script to get hard disk health in fedora/ubuntu

2014-12-01 2 min read Fedora Learning Linux

First, put this in a script.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash

#Change as appropriate
HDD=sda

export sub="SmartCtl data for HDD"
echo 'To: &lt;Your Email&gt;
Sub: [Cron] $sub
MIME-Version: 1.0
Content-Type: text/html
Content-Disposition: inline

&lt;html&gt;&lt;pre&gt;'


echo '&lt;style&gt;

hr {
    display: block;
    height: 1px;
    border: 0;
    border-top: 1px solid #ccc;
    margin: 1em 0;
    padding: 0;
}
&lt;/style&gt;
'

echo '&lt;h2&gt;Errors on HDD:&lt;/h2&gt;'
echo '&lt;hr&gt;'
sudo smartctl -l error  /dev/$HDD
echo '&lt;h2&gt;Health of HDD:&lt;/h2&gt;'
echo '&lt;hr&gt;'
sudo smartctl -H  /dev/$HDD

echo '&lt;h2&gt;Detailed info&lt;/h2&gt;'
echo '&lt;hr&gt;'
sudo smartctl -a -d ata /dev/$HDD

echo '&lt;h2&gt;Journalctl output for smartd&lt;/h2&gt;'
echo '&lt;hr&gt;'

if [[ -f /etc/fedora-release ]]
then
journalctl -x --show-cursor -u smartd --since=yesterday
else
#This is for Ubuntu.. still using dmesg

dmesg -T -l err,crit,alert,emerg

fi


echo '&lt;h2&gt;All Details&lt;/h2&gt;'
echo '&lt;hr&gt;'

sudo smartctl --xall /dev/$HDD


echo "Thanks for using Amit Agarwal's script"
echo '&lt;/pre&gt;&lt;/html&gt;'

and then put this in cron:

Continue reading

nall – schedule your tasks like a pro

2014-10-06 1 min read Fedora

nall is a utility to run your scripts ( for whatever ) every defined period. Here is description:

Description : Nall is a small gtk+ application that discretely fits into your freedesktop
system tray (such as trayer).
Its purpose is to spawn periodically every kind of script and display a
one-line output in the tooltip window. The main usage of nall is monitoring or
just notifying of almost everything (it just depends upon your imagination and
ability to script).

For installation :

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. So, how to at-least take a look at why these are failing, login with ssh.

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="~/mail"
if [[ $(wc -l $mailfile|awk '{print $1}' ) -ge 5 ]]
then
    to=$(grep ^To: $mailfile|sed 's/To: //')
    echo "Good to send mail... to = $to"
    sendmail -t <$mailfile
    echo "once mail is send, delete the contents of file"
    echo "sed -i '4,$ d' $mailfile"
fi

Now, create a file called mail in your home directory, with the following contents:

Continue reading

wordpress blog stats monitoring from remote using curl and bash and send it in mail.

2010-06-25 3 min read Bash Fedora Linux

Here&#8217;s something that I had been planning to do for sometime now. I have my blog on wordpress and have Statpress plugin installed. The plugin does give me a good idea of the visits to my site. Now, I have to keep logging in every now and then to check the stats. Also since I did not want to spend some more amount 🙂 so I do not have the shell access to the server, too bad 🙁

Continue reading
Older posts