文章标签 » linux

[bookmark]cron,anacron,atd

There’s a clear difference between these three applications, and merging
them would be a fairly significant amount of development effort.

cron – executes recurring commands that should occur at a specific time
anacron – executes recurring commands that should take place with a
given frequency.

(The difference between them is that if a task is scheduled in cron and
the machine is switched off, it won’t be executed until the next time
it’s due to run. anacron will attempt to catch up when the machine comes
back up)

atd – executes a non-recurring command at a specific time

The fact that all three exist is something of a holdover from legacy
Unix, but it’s not possible to just remove one of them.

http://ubuntu.5.x6.nabble.com/cron-atd-anacron-other-wtf-td686145.html

[转载]我眼中的各Linux发行版用户

我眼中的各Linux发行版用户

backup:更实用的大文件搜索

findbigfile.py

#!/usr/bin/env python
import sys, os
 
#100M
BIG_FILE_SIZE = 1024 * 1024 * 100
BIG_DIR_SIZE = int(os.popen('getconf PAGE_SIZE').read().strip()) * 1024
EXCLUDES = ['/home/cdn/wpt_data']
 
EXCLUDES = [os.path.normpath(p) for p in EXCLUDES]
stack = [os.path.normpath(sys.argv[1])] 
 
def format_size(s):
    if s < 1024:
        return '%d Bytes' % s
    if s < 1024 * 1024:
        return '%d KB' % (s/1024)
    if s < 1024 * 1024 * 1024:
    	return '%d MB' % (s/1024/1024)
    return '%d GB' % (s/1024/1024/1024)
 
while len(stack):
    check_file = stack.pop()
 
    if check_file in EXCLUDES:
        continue
 
    #pass link
    if os.path.islink(check_file):
        continue
 
    if os.path.isfile(check_file):
        s = os.path.getsize(check_file)
        if s > BIG_FILE_SIZE:
            print 'BIG FILE:%s\t%s' % (check_file, format_size(s))
        continue
 
    if os.path.isdir(check_file):
        s = os.path.getsize(check_file)
 
        #pass big directory
        if s > BIG_DIR_SIZE:
            print 'BIG DIR:%s\t%s' % (check_file, format_size(s))
            continue
 
        try:
            for f in os.listdir(check_file):
                stack.append(os.path.join(check_file, f))
        except:
            pass

backup:在linux下使用clang的闭包特性

FROM:http://stackoverflow.com/questions/5907071/clang-block-in-linux
On Ubuntu Linux:

sudo apt-get install llvm
sudo apt-get install clang
sudo apt-get install libblocksruntime-dev

test.c:

#include <stdio.h>
 
int main() {
    void (^hello)(void) = ^(void) {
        printf("Hello, block!\n");
    };
    hello();
    return 0;
}

compile:

clang test.c -fblocks -lBlocksRuntime -o test
./test
 
Hello, block!

works fine.

backup:linux下不输密码执行高权限命令

慎用!慎用!

conn_vpn.c

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
 
int main(int argc, const char **argv) {
    if (setuid(0) != 0) {
        fprintf(stderr, "setuid error\n");
        return 1;
    }
    char *oldpath = getenv("PATH");
    char *tmp = malloc(sizeof(char) * strlen(oldpath) + 100);
    tmp[0] = '\0';
    strcat(tmp, oldpath);
    strcat(tmp, ":/sbin:/usr/sbin");
    setenv("PATH", tmp, 1);
    free(tmp);
    execl("/usr/bin/pon", "/usr/bin/pon", "myvpn", NULL);
    return 0;
}
gcc conn_vpn.c -o conn_vpn
sudo chown root:root conn_vpn
sudo chmod +s conn_vpn