Archive for the ‘Linux’ Category

untar all files in a directory

for i in *.tar.gz; do echo extracting $i; tar xvzf $i ;

  • Share/Save/Bookmark

VirtualBox Fedora 13 install guest additions

Install packages needed

yum -y install kernel-devel kernel-headers dkms gcc gcc-c++
in VirtualBox devices, select install guest additions
sh VBoxLinuxAdditions.run

  • Share/Save/Bookmark

VirtualBox Fedora 13 guest use shared folder

Fedora 13 as guest OS on a Windows 7 host

Add a shared folder in virtualbox’s devices settings.
create a folder “Shared” in fedora
su –c “mount.vboxsf Shared ~/Shared -o rw,exec,uid=1000,gid=1000,dev”

  • Share/Save/Bookmark

Create multiple volumn zip backup with MD5 check

Download and install p7zip:
http://p7zip.sourceforge.net/

Then use 7z
Code:

7z a -v50m test.zip your-big-file-paths

this makes 50 MB volumes called
Code:

test.zip.001 test.zip.002 test.zip.003 test.zip.004

To extract them just run
Code:


7z x test.zip.001

make md5

# md5sum test.zip.* > MD5SUM
# cat MD5SUM
cb16175f4acad02f977f74d5c142879b test.zip.001
33c745ca49ab6e63b727658ec148cf67 test.zip.002
14e6952b632fbb7f4c0731067afdb46c test.zip.003
....

check md5

# md5sum --check MD5SUM

  • Share/Save/Bookmark

SVN make a sub folder to a seperate new repository


svnadmin dump /svn/old_repos > ./repository.dump
svndumpfilter include path/to/docs --drop-empty-revs --renumber-revs --preserve-revprops < ./repository.dump > ./docs_only.dump
svnadmin load /svn/new_repos < ./docs_only.dump

  • Share/Save/Bookmark

Open and edit files from remote server

In my workplace, every developer needs to work on own directory in a shared dev server.

Here is the command I ran to open my directory and edit my files remotely.

1
sshfs username@192.168.0.6:/remote/directory/path /mount/to/your/local/directory/path

* 192.168.0.6 is IP of remote server.

After you ran this, access to /mount/to/your/local/directory/path directory is same as access to remote directory.

Have fun. :)

  • Share/Save/Bookmark

Remove svn directories and files

Deleting all SVN files and directories is a headache if your project contains lots of directories.

Here is a easy way to delete them with one command.

1
find /path/to/your/directory -type d -name .svn -exec rm -rf '{}' +
  • Share/Save/Bookmark

cp file always getting overwrite prompt?

wondering why always getting overwrite prompt when use “cp” command with “-f” option

try this,

1. login as root

1
vi /root/.bashrc

2. comment out this line

1
#alias cp='cp -i'

3. logout and login again

  • Share/Save/Bookmark

Rsync server and client – backup your server files

rsync can synchronizes files and directories from one server to another. It’s perfectly for backup or create a mirror site purpose.

This tutorial shows you step by step to create a rsync server and client server.

First of all, you must have rsync installed. For fedora, rsync should be included by default. If you don’t have it, run

1
yum install rsync

Setup rsync server

Create rsync configuration file:

1
2
3
4
5
6
7
cd /etc
mkdir rsyncd
cd rsyncd
touch rsyncd.conf
touch rsyncd.motd
touch rsyncd.user
chmod 600 rsyncd.user

edit rsyncd.user file and create username and password:
vi /etc/rsyncd/rsyncd.user

1
my_rsync_user_1:user_1_password

edit rsyncd.conf file:

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
pid file=/var/run/rsyncd.pid
port=873
uid=root
gid=root
use chroot=yes
read only=yes
 
# limit access to LANS
hosts allow=192.168.2.0/255.255.255.0   #default, listen to lan server
host deny=*
 
max connections=5
motd file=/etc/rsyncd/rsyncd.motd
 
log format=%t%a%m%f%b
syslog facility=local3
timeout=300
 
[profile_1]          #profile name
path = /path/to/backup/directory
ignore errors
read only = false
list = false
hosts allow = 66.66.66.66   #listen to client server which use public ip
hosts deny = 0.0.0.0/32
auth users = my_rsync_user_1
secrets file = /etc/rsyncd/rsyncd.user
 
#[profile_1]          #another profile name
#path = /path/to/backup/directory/2
#ignore errors
#read only = false
#list = false
#hosts allow = 88.88.88.88   #listen to client server which use public ip
#hosts deny = 0.0.0.0/32
#auth users = my_rsync_user_2
#secrets file = /etc/rsyncd/rsyncd.user

Next, create init start up script
vi /etc/init.d/rsyncd

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
#!/bin/sh
#
# Startup script for rsyncd daemon
#
# chkconfig: 35 90 10
# description: Server data for sync to other server
# processname rsync
 
# Source function library
. /etc/rc.d/init.d/functions
 
prog=rsync
conf=/etc/rsyncd/rsyncd.conf
 
case "$1" in
    start)
        echo -n "Starting rsync daemon: "
        daemon /usr/bin/$prog --daemon --config=$conf
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
        ;;
    stop)
        echo -n "Shutting down $prog: "
        killproc -d 60 $prog
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog
        ;;
    status)
        status $prog
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac
 
exit 0

make /etc/init.d/rsyncd executable, and register this service

3
4
5
chmod +x /etc/init.d/rsyncd 
/sbin/chkconfig --add rsyncd
/sbin/service rsyncd start

Setup rsync client

first, of course you must have rsync installed on client server

make rsync password file

1
2
3
4
5
cd /etc
mkdir rsync
cd rsync
touch rsync.pwd
chmod 600 rsync.pwd

vi /etc/rsync/rsync.pwd

1
user_1_password

execute this command to start synchronize file to server

1
rsync -vrtLogp --progress /path/to/directory/to/be/backup/* my_rsync_user_1@[SERVER_IP]::profile_1 --password-file=/etc/rsync/rsync.pwd

where [SERVER_IP] is rsync server IP

  • Share/Save/Bookmark

Plesk common shell commands

Reload vhost.conf for single domain

1
/usr/local/psa/admin/sbin/websrvmng --reconfigure-vhost --vhost-name=

Update AWStats for only 1 domain in Plesk

1
/usr/local/psa/admin/sbin/statistics --calculate-one --domain-name=you-domain.com
  • Share/Save/Bookmark