August 5, 2010 | Posted by
admin | Category: Linux Administration
Linux provides a command called “history” to view the previously executed commands on shell. By default, the “history” command display only the commands that were executed but not the date and time when they were executed.
To display the time and date of the previously executed commands, you need to set the “HISTTIMEFORMAT” variable. The variable has to be set in the users profile file so to take effect on each session.
To set the “HISTTIMEFORMAT” variable, SSH to your server and execute:
# export HISTTIMEFORMAT="[%F] [%T] "
You can also insert the above line at the end of the .bash_profile file
# vi /root/.bash_profile
Once the file is saved, open a new SSH session and execute the ‘history’ command to view the timestamp of the previously executed commands.
For example:
root@server [~]# history
1068 [2010-08-05] [07:17:04] ps -auxf
1069 [2010-08-05] [07:17:06] top c
1070 [2010-08-05] [07:17:35] ll
1071 [2010-08-05] [07:37:51] ls -la
1072 [2010-08-05] [07:41:37] cat /root/.bash_profile
1073 [2010-08-05] [07:41:47] cd
The commands in the above output is just an example.
August 1, 2010 | Posted by
admin | Category: Linux Administration
The default firewall of Linux is iptables which can be use to block Ftp access/port on your server. If you have a CSF firewall (which also use iptables), see section 2.
Section 1: Iptables
Completely block Ftp access on the server:
# iptables -A INPUT -p tcp --dport 21 -j DROP
Block Ftp access for a specific IP address, say 11.12.13.14
# iptables -A INPUT -p tcp -s 11.12.13.14 --dport 21 -j DROP
Block Ftp access for a specific subnet
# iptables -I INPUT -p tcp -s 11.12.13.0/24 --dport 21 -j DROP
The rules need to be saved else they will be removed if the iptables service is restarted.
# service iptables save
Section 2: CSF
To completely block Ftp access, edit csf.conf file and remove port 21 from the TCP_IN list
# pico /etc/csf/csf.conf
To block Ftp access for a specific IP address, edit the csf.deny file
# pico /etc/csf/csf.deny
and place the following line
tcp:in:d=21:s=11.12.13.14
Save the file and don’t forget to restart the firewall.
Comments Off on How to Block Ftp Access/Port using iptables OR CSF?
July 27, 2010 | Posted by
admin | Category: Linux Administration
dmidecode command can be used to check the system’s information and manufacturers of MotherBoard, Processor, RAM and other hardware of your Linux server. If the dmidecode command doesn’t work, install it using YUM.
Check your Linux server architecture i.e. 32bit OR 64bit:
# uname -p
Search for the dmidecode package
# yum search dmidecode
Depending on the architecture, install the proper dmidecode package
# yum install dmidecode
You are done. To check all the hardware information of the server, execute
# dmidecode
Comments Off on How to check System Information and vendors of MotherBoard/Processor/RAM in Linux?
July 25, 2010 | Posted by
admin | Category: Plesk Management
You see a “Unable to install the psa-backup-manager” error while installing Plesk control panel on a Linux server and it is because of the incomplete db4 packages needed for embedded database support for various applications. The complete error message looks like:
Determining the packages that need to be installed. ERROR: Unable to
install the "psa-backup-manager-9.x.x-cos5.buildxxxxxxx.00.i586"
package. Not all packages were installed.
Solution:
Check if the required db4 packages are installed by executing:
# rpm -qa | grep db4
It will list the db4 packages. If the db4-devel and db4-utils are missing from the above output, install the packages using yum
# yum install db4-utils
# yum install db4-devel
That’s it. You can start the Plesk installation once again and it will install the psa-backup-manager successfully.
Comments Off on Plesk Installation: Unable to install the psa-backup-manager
July 23, 2010 | Posted by
admin | Category: Scripts
The following shell script will dump the mysql database and will save the .sql file on a remote location using Ftp. This script will create a backup file including the current date so you can have multiple copies of the backups of the same database under one directory.
Create a file called mysqlbkup.sh
# vi /root/mysqlbkup.sh
and paste the following code in the file as it is.
##############START OF THE SCRIPT##############
#!/bin/bash
# Specify the temporary backup directory.
BKUPDIR="/tmp"
# Specify Database Name
dbname="dbname_here"
# Save the current date
date=`date '+%Y-%m-%d'`
# Specify Ftp details of the remote server.
ftpserver="FtpServerIP"
ftpuser="your ftp user"
ftppass="your ftp password"
# Dump the mysql database with the current date and compress it.
# Save the mysql password in a file and specify the password file
# path in the below command.
/usr/bin/mysqldump -uroot -p`cat /path/to/pass/file` $dbname\
| gzip > $BKUPDIR/$date.$dbname.sql.gz
# Change directory to the backup directory.
cd $BKUPDIR
# Upload the backup
ftp -n $ftpserver <<!EOF!
user $ftpuser $ftppass
binary
prompt
mput *.sql.gz
quit
!EOF!
# Remove the local backup file.
/bin/rm -f /$BKUPDIR/$date.$dbname.sql.gz
##############END OF THE SCRIPT##############
Make sure to specify your db_name, ftpserver, ftpuser and ftppass values in the script.
Save the file and schedule a cronjob to execute the file on daily basis, say during night hours at 1.00AM. Edit the cron file
# crontab -e
and set the following cronjob
0 1 * * * /bin/sh /root/mysqlbkup.sh
save the file and restart the crond service
# service crond service
The script will work on a Linux/Plesk server as well. You just have to replace the mysqldump line in the script with the following
/usr/bin/mysqldump -uadmin -p`cat /etc/psa/.psa.shadow` $dbname\
| gzip > $BKUPDIR/$date.$dbname.sql.gz
Note: Leave a comment if you have any suggestions, questions OR have received any error message using this script.