Bash script to find all broken links or a wesite

#/bin/bash
#Usage find_broken_links.sh URL

if [ $# -eq 0 ];
then
printf “Usage $0 URL \n Example http://mydomain.com \n”;
exit -1;
fi

mkdir -v /tmp/$$.lynx;
cd /tmp/$$.lynx;

lynx -traversal $1 >/dev/null
sort -u reject.dat >all_rejected_links.txt

count=0;
echo “Broken links are :”

while read link;
do
flag=`curl -I $link -s | grep “HTTP/.*OK”`;
if [[ -z $flag ]]; then
echo $link;
[[count++]];
fi

done < all_rejected_links.txt

if [ $count -eq 0 ]; then
echo “No broken links !”
fi

Fun with Linux Terminal :)

Working Linux is really fun and you can make impression on windows kids wit the below commands and applications !

1) Have a train on your terminal

yum install sl

Than use the command sl on terminal.

Train

2) A telnet movie

 

telnet towel.blinkenlights.nl

                                           /~\
                                          |oo )
                                          _\=/_
                          ___        #   /  _  \  #
                         / ()\        \\//|/.\|\\//
                       _|_____|_       \/  \_/  \/
                      | | === | |         |\ /|
                      |_|  O  |_|         \_ _/
                       ||  O  ||          | | |
                       ||__*__||          | | |
                      |~ \___/ ~|         []|[]
                      /=\ /=\ /=\         | | |
      ________________[_]_[_]_[_]________/_]_[_\_________________________^]

3) Reverse texts

[root@nopanel ~]# rev
Deepak
kapeeD

 

4) ASCII cow 

You can install this from EPEL repository

saycow

 

5)  Create your own Matrix Hack with cmatrix

Installation :-

yum install gcc make autoconf automake ncurses-devel

wget http://www.asty.org/cmatrix/dist/cmatrix-1.2a.tar.gz

tar xvzf ~/cmatrix-1.2a.tar.gz

cd ~/cmatrix-1.2a
aclocal
autoconf
automake -a
./configure
make
sudo make install

Just type command cmatrix  and have fun with matrix

cmatrix

 

6) banner cimmand

banner – prints a short string to the console in very large letters

banner

7) Ascii art with “figlet” 

rpm -Uvh http://pkgs.repoforge.org/figlet/figlet-2.2.2-1.el6.rf.x86_64.rpm

figlet

 

8) cowsay/cowthink – configurable speaking/thinking cow

cowsay

9) fortune – print a random, hopefully interesting, adage

fortune

10) aafire displays burning ascii art flames

Installation :-

Will get from rpmforge
# yum install aalib

Just type aafire to bring fire on your terminal

aafire

11) espeak – A multi-lingual software speech synthesizer.

espeak “Linux is Cool”

12) Factor, Print the prime factors of each specified integer NUMBER
[root@nopanel ~]# factor
5
5: 5
10
10: 2 5
11
11: 11

12) Clock with figlet and while loop

Use the oneliner:  while true; do echo “$(date ‘+%D %T’ | figlet)”; sleep 1; done

Clock

 

13) ASCIIquarium : Have a live ASCII aquarium

Installation :-

cpan Term::Animation

wget http://www.robobunny.com/projects/asciiquarium/asciiquarium.tar.gz
tar -zxvf asciiquarium.tar.gz
cd asciiquarium_1.1/
cp asciiquarium /usr/local/bin
chmod 0755 /usr/local/bin/asciiquarium

Just type command “asciiquarium” and have an aquarium on your terminal

aquarium

Enable HTML Editor in Horde (cPanel)

1) Open the file /usr/local/cpanel/base/horde/imp/config/mime_drivers.php

2) Change “‘inline’ => falce,” to “‘inline’ => true,” as below and save the file.
$mime_drivers[‘imp’][‘html’] = array(
‘inline’ => true,
:
:
3) Restart cPanel service : /etc/init.d/cpanel restart

4) Restart IMAP : /scripts/restartsrv courier

 

 

 

PHP script to take Database backup

<?php
$datestamp = date(“Y-m-d”);     // Current date to append to filename of backup file in format of YYYY-MM-DD

/* CONFIGURE THE FOLLOWING FOUR VARIABLES TO MATCH YOUR SETUP */
$dbuser = “database_username”;     // Database username
$dbpwd = “database_password”;     // Database password
$dbname = “database_name”;     // Database name. Use –all-databases if you have more than one
$filename = “backup-$datestamp.sql.gz”;     // The name (and optionally path) of the dump file

$command = “mysqldump -u $dbuser –password=$dbpwd $dbname | gzip > $filename”;
$result = passthru($command);
?>

 

 

Get mail statistics from your postfix mail logs

pflogsumm is designed to provide an over-view of postfix activity, with just enough detail to give the administrator a “heads up” for potential trouble spots.

1) wget http://pkgs.fedoraproject.org/repo/pkgs/postfix/pflogsumm-1.1.1.tar.gz/2f570477b2e205f9dfc1df13f00b5c0d/pflogsumm-1.1.1.tar.gz
tar xzvf pflogsumm-1.1.1.tar.gz
cd pflogsumm-1.1.1

2) Just pass the mail log to the perl script🙂

cat /usr/local/psa/var/log/maillog | ./pflogsumm.pl

 

 

Convert UNIX Epoch Time on *NIX Log files

This is very simple with Perl, the part “([\d.]+)” is matching and then converting to localtime, then replacing the previous match, did🙂

 

#cat input.txt;

[ 1393157883 ] [ alphacub_kjuy7f8 ] [ 925734 ] [ 133 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393163641 ] [ alphacub_kjuy7f8 ] [ 1001850 ] [ 62 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [  ] [  ]
[ 1393163821 ] [ alphacub_kjuy7f8 ] [ 797986 ] [ 147 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [  ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 1110922 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 1108704 ] [ 103 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 934769 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 798257 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 798129 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 797548 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]
[ 1393164363 ] [ alphacub_kjuy7f8 ] [ 797086 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ 'server.example.com' ] [  ]

#cat input.txt | perl -ne ‘use POSIX; s/([\d.]+)/strftime “%Y-%m-%d %H:%M:%S”, localtime $1/e,print if /./’

[ 2014-02-23 06:18:03 ] [ alphacub_kjuy7f8 ] [ 925734 ] [ 133 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 07:54:01 ] [ alphacub_kjuy7f8 ] [ 1001850 ] [ 62 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ] [ ]
[ 2014-02-23 07:57:01 ] [ alphacub_kjuy7f8 ] [ 797986 ] [ 147 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 1110922 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 1108704 ] [ 103 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 934769 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 798257 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 798129 ] [ 104 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 797548 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]
[ 2014-02-23 08:06:03 ] [ alphacub_kjuy7f8 ] [ 797086 ] [ 105 ] [ alphacub_cubire ] [ Sleep ] [ KILLED ] [ ‘server.example.com’ ] [ ]

Fun with BASH

# make fire
make: *** No rule to make target `fire’.  Stop.

# \(-
bash: (-: command not found

# sh
sh-4.1# PATH=pretending! /usr/bin/which sense
/usr/bin/which: no sense in (pretending!)

# nice man woman
No manual entry for woman

# [ Where is Deepak Tom?
bash: [: missing `]’

# make love
make: *** No rule to make target `love’.  Stop.

# touch /pussy
touch: cannot touch `/pussy’: Permission denied