31 Mar 2010

rsync modules

Dùng cái này
#!/usr/bin/python
import os
root = '/home/'
names = os.listdir(root)
#names = open('/mnt/data/names.txt','r')
names.sort()
for line in names:
#    if not line:
#        break
    if not os.path.isdir(root + line):
        continue
    if line == 'lost+found':
        continue
    print "[" "%s" "]" %line
    print '        comment = ''%s' %line
    print '        path ='+root +line
    print """        use chroot = yes  
        max connections=10  
        lock file = /var/lock/rsyncd  
        read only = no  
        list = yes 
              """
    print '        uid= '+line
    print '        gid= '+line
    print """        ignore errors = no  
        ignore nonreadable = yes  
        transfer logging = no  
        log format = %t: host %h (%a) %o %f (%l bytes). Total %b bytes.  
        timeout = 600  
        refuse options = checksum dry-run  
        dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz  
              """

với cái này sẽ tiết kiệm được chút thời gian và công sức :).

29 Mar 2010

Bị tấn công

Kiểm tra /var/log/messages thì phát hiện ra cái này http://pastebin.com/Wz8LE7tW
Cái hơi hay ho ở đây là log trên của laptop. Không biết bạn nào rảnh đi brute force ssh laptop của mình ;))

6 Mar 2010

Stupid

Just updated my gentoo box and some features get problem. All should be solved by running "revdep-rebuild" to re-install some missing library. But there's an interesting bug (?) of wicd after update :). You cannot start wicd daemon with error
g3n2 ~ # /etc/init.d/wicd restart
/etc/init.d/wicd: line 12: syntax error: unexpected end of file
 * ERROR:  /etc/init.d/wicd has syntax errors in it; aborting ...
Take a look at wicd init script, someone who made update for wicd did make a mistake:
#!/sbin/runscript
 2 # Copyright 1999-2006 Gentoo Foundation
 3 # Distributed under the terms of the GNU General Public License v2
 4 
 5 opts="start stop restart"
 6 
 7 WICD_DAEMON=/usr/sbin/wicd
 8 WICD_PIDFILE=/var/run/wicd/wicd.pid
 9 
10 depend() {

11                   need dbus
Function depend() has no close parenthesis, and where is start() and stop() function? I don't know.I solved it by adding some line like bellow:
1 #!/sbin/runscript
 2 # Copyright 1999-2006 Gentoo Foundation
 3 # Distributed under the terms of the GNU General Public License v2
 4 
 5 opts="start stop restart"
 6 
 7 WICD_DAEMON=/usr/sbin/wicd
 8 WICD_PIDFILE=/var/run/wicd/wicd.pid
 9 
10 depend() {
11     need dbus
12     }
13 start() {
14             ebegin "Starting wicd daemon"
15                     "${WICD_DAEMON}" >/dev/null 2>&1
16                             eend $?
17 }
18 
19 stop() {
20             ebegin "Stopping wicd daemon"
21                     start-stop-daemon --stop --pidfile "${WICD_PIDFILE}"
22                             eend $?
23 }
Who works for the maintenance of wicd on gentoo? wtf

4 Mar 2010

portage-2.1.8 has new --rebuilt-binaries option

In portage-2.1.8 there's a new emerge --rebuilt-binaries
option that is very useful for people who build binary packages and
install them on multiple computers (using PORTAGE_BINHOST or shared
PKGDIR). The option causes packages to be automatically reinstalled in
cases when rebuilt binary packages are available (due to revdep-rebuild
or similar cases).
Rebuilds are detected by comparison of BUILD_TIME package metadata.
This option is enabled automatically when using binary packages
(--usepkgonly or --getbinpkgonly) together with --update and --deep.


http://blogs.gentoo.org/zmedico/2010/03/03/rebuilt_binaries_portage_2_1-8

12 Feb 2010

Love songs

#!/usr/bin/env python
# python script to download love songs from mp3.zing.vn
# hungnv
# license: Public Domain
from urllib2 import urlopen
from urllib import urlretrieve
from os import mkdir
from os.path import join, isdir
import sys
mp3_dir = "/home/hungnv/Music/"
html_source = "http://mp3.zing.vn/mp3/nghe-album/album-hot/love-song.html"
if not isdir(mp3_dir):
    try:
        mkdir(mp3_dir)
    except:
        print "cannot create directory %s" %mp3_dir
        sys.exit(1) 
def getlink():
    try:
        response = urlopen(html_source)
    except:
        print "connection error"
    response = urlopen(html_source)
    content = response.readlines()
    response.close()
    for line in content:
        a = line.find('http://dl.mp3.kapsule.info')
        b = line.find('?')
        if a <> -1 and b <> -1:
            link = line[a:b]
            c = line.find('filename') + 9
            d = line.find('alt') - 2
            filename = line[c:d]
            print "Song named %s will be downloaded at url %s" % (filename,link)
            print "Downloading.....\n"
            abs_path = join(mp3_dir,filename)
            urlretrieve(link,abs_path)
        else:
            continue
if __name__ == '__main__': 
    getlink()
exit()

27 Jan 2010

Indispensable job

I have an account named hungnv on my server - vndev.net which's running Fedora 8. If I want to remote copy, modify, delete... some files on this server , which way is faster:
1. sftp ( known as an extension of secure shell protocol - SSH ) 
hungnv@g3n2 ~ $ sftp vndev.net
Connecting to vndev.net...
sftp>
Browse local file: lls, move to local directory lcd
upload put
download get

2. sshfs (not an ssh extension, we must install fuse-sshfs to use it)
hungnv@g3n2 ~ $ eix sshfs
[I] sys-fs/sshfs-fuse
     Available versions:  1.9 ~2.1 2.2
     Installed versions:  2.2(08:46:14 AM 01/27/2010)
     Homepage:            http://fuse.sourceforge.net/sshfs.html
     Description:         Fuse-filesystem utilizing the sftp service.
hungnv@g3n2 ~ $ sudo emerge -av sys-fs/sshfs-fuse
hungnv@g3n2 ~ $ sshfs vndev.net:/ /vndev
to mount. We browse, cp, edit, delete....like local file and directory.
I didn't use sshfs until yesterday, with me, ssh and sftp are enough. But I should know sshfs and I did not know, so I fail.
We must learn what we never use =.=

Disqus