Mohammedz.com

For Linux and Shell scripting.


Leave a comment

How to find past/future dates?

what day it was exactly one month ago? Are you counting down the days to find it? Or searching for a calender?

You can use “date” command in such situations. See the example below:

****************************************
-bash-3.1$ date +%F
2009-06-29
-bash-3.1$ date -d”1 day ago” +%F
2009-06-28
-bash-3.1$ date -d”1 week ago” +%F
2009-06-22
-bash-3.1$ date -d”1 month ago” +%F
2009-05-29
-bash-3.1$ date -d”1 year ago” +%F
2008-06-29
-bash-3.1$
****************************************

These examples will show you how to find the future dates.
****************************************
-bash-3.1$
-bash-3.1$ date +%F
2009-06-29
-bash-3.1$ date -d”-1 day ago” +%F
2009-06-30
-bash-3.1$ date -d”-1 week ago” +%F
2009-07-06
-bash-3.1$ date -d”-1 month ago” +%F
2009-07-29
-bash-3.1$ date -d”-1 year ago” +%F
2010-06-29
-bash-3.1$
****************************************

~mohammed


Leave a comment

Apache: how to disable directory listing

Disable directory listing using httpd.conf:
* Open your httpd.conf and look for “Options Indexes”
* Change “Indexes” to “-Indexes” if it exists.
* Or else add “Options -Indexes” as a new line
* Restart your apache webserver

Disable directory listing using .htaccess:-
* Open your .htacces file and look for “Options Indexes”
* Change “Indexes” to “-Indexes” if it exists.
* Or else add “Options -Indexes” as a new line

Regards,
Mohammed.


Leave a comment

Array manipulation in shell scripting

Best way to understand shell scripting is from examples. Find the example below to understand different options available in bash array manipulation.

You can down this script from here.
*********************************
#!/bin/bash

array=(one two three four [5]=five)

echo “Array size: ${#array[*]}”

echo “Array items:”
for item in ${array[*]}
do
printf ” %s\n” $item
done

echo “Array indexes:”
for index in ${!array[*]}
do
printf ” %d\n” $index
done

echo “Array items and indexes:”
for index in ${!array[*]}
do
printf “%4d: %s\n” $index ${array[index]}
#printf “%4d: %s\n” $index ${array[$index]}
done
*********************************

Regards,
Mohammed.


Leave a comment

HISTTIMEFORMAT: add execution time to Linux’s history file

As you might know, Linux logs all the commands executed on a shell prompt to its history file. The file is .bash_history by default, but you can change it. Also, you can change HISTTIMEFORMAT to enable timestamping to history.

If you add the following line to your bashrc or bash_profile, the time stamp information associated with each history entry will be written to the history file.

HISTTIMEFORMAT=”%h-%d-%Y – %H:%M:%S ”

Regards,
Mohammed.


Leave a comment

Bash script to backup mysql databases

Here is a bash script to backup all mysql databases, including mysqlcheck.

The script has the following advantages:
* It will list all databases and will dump them separately
* all backups will be stored under /root/mysql_backups/
* backups will run on a daily rotational basis over 7days
* old backups will be removed only after completing new backup processes.
* you can enable or disable mysqlcheck
* separate log files for mysqlcheck and dump processes.
* option to enable or disable email alerts on success and failure

You can download the script from here.

Regards,
Mohammed


Leave a comment

!!! Chelsea !!!

Chelsea FC

[picapp src=”f/a/c/1/PicImg_Chelsea_Team_Group_ca65.JPG?adImageId=6032956&imageId=4111834″ width=”500″ height=”333″ /]

Chelsea players lift Community Shield 2009

[picapp src=”5/b/1/d/CHELSEA_V_MANCHESER_a514.JPG?adImageId=6029972&imageId=5889710″ width=”500″ height=”336″ /]

John Terry

[picapp src=”2/d/c/0/CHELSEA_V_MANCHESER_9e33.JPG?adImageId=6030586&imageId=5888890″ width=”500″ height=”732″ /]

[picapp src=”7/4/e/4/Football__FC_7045.JPG?adImageId=6031161&imageId=4674209″ width=”500″ height=”368″ /]

Frank Lampard

[picapp src=”0/3/2/7/PicImg_Football__Chelsea_634d.JPG?adImageId=6032098&imageId=4126358″ width=”500″ height=”769″ /]

[picapp src=”6/e/4/2/PicImg_Football__Chelsea_12fb.JPG?adImageId=6032206&imageId=4126279″ width=”500″ height=”334″ /]


Leave a comment

Restore primary partition table without overwriting the MBR

You can find this useful information from the manpage for gpart.

The gpart may be of some help when the primary partition table was lost or destroyed but it can under no circumstances replace proper disk/partition  table  backups. To save the master boot record (MBR) including the primary partition table to a file type

dd if=/dev/hda of=mbr bs=512 count=1

Exchanging /dev/hda with the block device name of the disk in question. This should be done for all disks in the system. To restore the primary partition table without overwriting the MBR type

dd if=mbr of=/dev/hda bs=1 count=64 skip=446 seek=446

Warning: make sure that all parameters are typed as shown and that the disk device is correct. Failing to do so may result in severe filesystem  corruption. The saved file should be stored in a safe place like a floppy disk.

~mohammed


Leave a comment

WordPress: password protect your posts

Do you want to protect your posts/articles with passwords? It’s much simpler than Joomla method. In wordpress, you can do it in any of the following methods.

When you Edit a post, under the Publish module (next to Visibility), click on
the Edit link. Select the Password Protected box and enter the password.

When you use Quick Edit on a post, there’s a field for the password.

~mohammed