TMOUT: How to set auto-logout time for SSH sessions

14 11 2009

If you want to set timeouts for user sessions on your Linux machine, you can use the variable TMOUT. You can set a value for TMOUT in bash_profile or bashrc file.

# auto-logout if the shell session is idle for 1 hour
TMOUT=3600

~mohammed





How to find past/future dates?

11 11 2009

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





Apache: how to disable directory listing

8 11 2009

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.





Array manipulation in shell scripting

8 11 2009

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.





HISTTIMEFORMAT: add execution time to Linux’s history file

7 11 2009

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.





Rsnapshot: mysql backup script

5 11 2009

Here is a bash script to backup all MySQL databases from a remote Linux/Unix machine through rsnapshot tool. This is written to work with rsnapshot, but you should be able to modify this to run individually.

You can download the script from here.

Regards,
Mohammed.





Bash script to backup mysql databases

5 11 2009

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





!!! Chelsea !!!

18 10 2009

Chelsea FC

Chelsea players lift Community Shield 2009

John Terry

Frank Lampard





Restore primary partition table without overwriting the MBR

13 10 2009

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





WordPress: password protect your posts

7 10 2009

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