#!/usr/bin/env python
import re, os
from urllib2 import urlopen
all_tag = []
def search_tag():
index_page = 'http://wallbase.net'
try:
_page_ = urlopen(index_page)
_html_ = _page_.readlines()
_page_.close()
p = re.compile(r'http://wallbase\.net/search/[a-z]+\"')
for line in _html_:
tag = p.findall(line)
if tag:
for i in tag:
all_tag.append(i[:-1a])
else:
continue
except Exception, e:
print "Connection Error!" + str(e)
def getsession(num):
org_url = "http://wallbase.net/wallpaper/"
second_url = org_url + num
_prefix = "http://wallpapers.yotoon.pl/rozne/"
ext = '.jpg'
fullname = "wallpaper-" + num + ext
try:
_page_ = urlopen(second_url)
_html_ = _page_.readlines()
_page_.close()
for line in _html_:
st = line.find(_prefix)
nd = line.find(fullname)
if st <> -1 and nd <> -1:
final = line[st:nd] + fullname
print final
os.system('wget ' + final)
else:
continue
except Exception, e:
print "Cannot connect to server!" + str(e)
pass
def getnum(list_tag):
for page in list_tag:
try:
response = urlopen(page)
content = response.readlines()
response.close()
for line in content:
a = line.find('thumb-')
b = line.find('jpg')
if a <> -1 and b <> -1:
c = a + 6
d = b - 1
number= line[c:d]
getsession(number)
continue
else:
continue
except:
print "May be we got wrong image url!"
if __name__ == '__main__':
search_tag()
getnum(all_tag)
exit()
Net chậm thì down chắc mất cả tháng :-D
26 Jun 2010
Down hết hình trên wallbase.net
9 Jun 2010
Nagios plugin
1st time I try to write plugin for nagios, it's really easy and simple with python :-). If you dont know how to use, please read this
First, check if we can reach website, then count response time and return nagios status.
First, check if we can reach website, then count response time and return nagios status.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Hung Nguyen Van
# 09-06-2010
from urllib2 import urlopen
import time, sys, socket
def timer(_dest):
timeout = 10
socket.setdefaulttimeout(timeout)
try:
_response = urlopen(_dest)
except:
print "CRITICAL: Cannot connect to server!"
sys.exit(3)
start_time = time.time()
_response = urlopen(_dest)
end_time = time.time()
final = end_time - start_time
return final
if __name__ == '__main__':
_dest = "https://" + sys.argv[1]
seconds = timer(_dest)
if seconds >= 10.0:
print "CRITICAL: Server took %.2f seconds to response" % (seconds)
sys.exit(2)
if seconds >= 7.0:
print "WARNING: Server took %.2f seconds to response" % (seconds)
sys.exit(1)
else:
print "OK: Server took %.2f seconds to response" % (seconds)
sys.exit(0)
19 May 2010
Clone hard disk
With dd_rescue, this task becomes more easy.
1. boot into a Linux LiveCD, use fdisk -l to identify your hard disks, if /dev/sda is the old one, and /dev/sdb is the new one, go to next step
2. install sys-fs/ddrescue, and clone the disk
3. almost finish, remove the old one, boot into the new one, your os should be ok.
4. another task: if new hard drive is bigger than the old one, free space will not be used, you will see it as free space, create new partition and mount it, or resize current partitions.
5. if you're using LVM2 for your system, read this
1. boot into a Linux LiveCD, use fdisk -l to identify your hard disks, if /dev/sda is the old one, and /dev/sdb is the new one, go to next step
2. install sys-fs/ddrescue, and clone the disk
ddrescue -v /dev/sda /dev/sdb
this task will complete after 2 hours or less if the old one is 80GB hard disk (in my case)3. almost finish, remove the old one, boot into the new one, your os should be ok.
4. another task: if new hard drive is bigger than the old one, free space will not be used, you will see it as free space, create new partition and mount it, or resize current partitions.
5. if you're using LVM2 for your system, read this
11 May 2010
lump
Lâu lắm rồi không cafe về đêm (khoảng giữa 9h đêm cho đến khuya), cũng rất hiếm khi ra ngoài quá 11h, đi chả để làm gì, mà về cũng chả để làm gì, ngoan lạ.
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 ;))
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
Subscribe to:
Posts (Atom)