XiZi's Blog

修改linux的时间显示格式

1、 设置时间样式

export TIME_STYLE=long-iso

Beatiful. Worked lika charm. Just wish I’ve looked into this earlier. Like a few years ago… Oh, well.

2、其他方式可以参考如下网页

How do I set the date format to ISO globally in Linux?

QEMU Service on Centos

1.先放个配置文件上来

# /etc/qemu.conf
# VMs that should be started on boot
# use the ! prefix to disable starting/stopping a VM
# QEMU_MACHINES=(kms)
QEMU_MACHINES=(kms)

# NOTE: following options will be prepended to qemu_${vm}
# -name ${vm} -pidfile /var/run/qemu/${vm}.pid -daemonize -nographic

qemu_kms_type="system-x86_64"

qemu_kms="-enable-kvm -hda /opt/qemu/kmsm4WOen.rom \
  -smbios type=1,manufacturer=Intel,version=1.01234,uuid=564d81c6-cd3a-d8e4-db29-756df139acb9 \
  -uuid 564d81c6-cd3a-d8e4-db29-756df139acb9 \
  -net nic -net user,hostfwd=tcp::1688-:1688 \
  -m 256 -rtc base=localtime,clock=host -M pc \
  -monitor telnet:localhost:7100,server,nowait,nodelay"
qemu_kms_haltcmd="echo 'system_powerdown' | nc localhost 7100" # or netcat/ncat

2.服务所需文件。

#!/bin/sh
# /etc/init.d/qemu

. /etc/rc.d/init.d/functions

[ -f /etc/qemu.conf ] && source /etc/qemu.conf

piddir=/var/run/qemu
lock='/var/lock/subsys/qemu-1.5rc1'
QEMU_PATH=/opt/qemu/qemu-1.5rc1
QEMU_DEFAULT_FLAGS='-name ${vm} -pidfile ${piddir}/${vm}.pid -daemonize -vga none -display none'
# -nographic
QEMU_HALTCMD_WAIT=30

case "$1" in
  start)
    [ -d "${piddir}" ] || mkdir -p "${piddir}"
    if [ -f $lock ]; then 
        # we were not shut down correctly 
        for pidf in `/bin/ls $piddir/*.pid 2>/dev/null`; do 
          if [ -s $pidf ]; then 
            kill `cat $pidf` >/dev/null 2>&1 
          fi 
          rm -f $pidf 
        done 
        rm -f $lock 
        sleep 2 
    fi 
    rm -f $piddir/*.pid 
    errors=0
    sucesses=0
    for vm in "${QEMU_MACHINES[@]}"; do
        if [ "${vm}" = "${vm#!}" ]; then
        echo -n $"Starting QEMU VM: ${vm}"
        eval vm_cmdline="\$qemu_${vm}"
        eval vm_type="\$qemu_${vm}_type"

        if [ -n "${vm_type}" ]; then
           vm_cmd="${QEMU_PATH}/bin/qemu-${vm_type}"
        else
           vm_cmd="${QEMU_PATH}/bin/qemu"
        fi

        eval "qemu_flags=\"${QEMU_DEFAULT_FLAGS}\""

        ${vm_cmd} ${qemu_flags} ${vm_cmdline} >/dev/null

        if [ $? = 0 ]; then
            successes=1
        else
            errors=1
        fi
       fi
    done
    
    if [ $errors = 1 ]; then
        failure; echo
    else
        success; echo
    fi
    if [ $successes = 1 ]; then
        touch $lock
    fi

    ;;

  stop)
    for vm in "${QEMU_MACHINES[@]}"; do
      if [ "${vm}" = "${vm#!}" ]; then
        # check pidfile presence and permissions
        if [ ! -r "${piddir}/${vm}.pid" ]; then
          continue
        fi

        echo -n $"Stopping QEMU VM: ${vm}"

        eval vm_haltcmd="\$qemu_${vm}_haltcmd"
        eval vm_haltcmd_wait="\$qemu_${vm}_haltcmd_wait"
        vm_haltcmd_wait=${vm_haltcmd_wait:-${QEMU_HALTCMD_WAIT}}
        vm_pid=$(cat ${piddir}/${vm}.pid)
  
        # check process existence
        if ! kill -0 ${vm_pid} 2>/dev/null; then
          stat_done
          rm -f "${piddir}/${vm}.pid"
          continue
        fi

        # Try to shutdown VM safely
        _vm_running='yes'
        if [ -n "${vm_haltcmd}" ]; then
          eval ${vm_haltcmd} >/dev/null

          _w=0
          while [ "${_w}" -lt "${vm_haltcmd_wait}" ]; do
            sleep 1
            if ! kill -0 ${vm_pid} 2>/dev/null; then
              # no such process
              _vm_running=''
              break
            fi
            _w=$((_w + 1))
          done

        else
          # No haltcmd - kill VM unsafely
          _vm_running='yes'
        fi

        if [ -n "${_vm_running}" ]; then
            # kill VM unsafely
            kill ${vm_pid} 2>/dev/null
            sleep 1
        fi

        # report status
        if kill -0 ${vm_pid} 2>/dev/null; then
          # VM is still alive
          #kill -9 ${vm_pid}
          failure; echo
        else
          success; echo
        fi

        # remove pidfile
        rm -f "${piddir}/${vm}.pid"
      fi
    done
    rm -f $lock
    ;;

  restart)
    $0 stop
    sleep 1
    $0 start
    ;;

  *)
    echo "usage: $0 {start|stop|restart}"

esac

PS:

# 如果你没安装过nc的话,就yum一下要么nc用不了,无法关闭服务器。
# 
yum install -y nc

goagent linux service script

 

#!/bin/bash
#
# file /etc/init.d/goagentd
# goagentd		Start up the goagentd server daemon
#
# chkconfig: 2345 55 25
# description: goagentd
#
# processname: proxy.py
# pidfile: /var/run/goagentd.pid

### BEGIN INIT INFO
# Provides: goagentd
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GoAgent
# Description:       GoAgent GAE Proxy Server.
### END INIT INFO

# source function library
. /etc/rc.d/init.d/functions

prog="goagent"
PYTHON=python
proxy=/opt/goagent/local/proxy.py
log=/opt/goagent/local/log

runlevel=$(set -- $(runlevel); eval "echo \$$#" )

start()
{
	echo -n $"Starting $prog: "
	[ -f "$log" ] && mv -f "$log" "$log.old"
	$PYTHON $proxy 1>&$log 2>&1 &
	touch /var/lock/subsys/goagent
}

stop()
{
	echo -n $"Stopping $prog: "
	kill $(ps aux | grep "[p]ython $proxy" | awk '{print $2}')
	rm -f /var/lock/subsys/goagent
}

restart() {
	stop
	start
}


case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	*)
		echo $"Usage: $0 {start|stop|restart}"
esac
exit 0

Fortran Makefile in Linux

 

FC = ifort
FFLAGS = -O2

ALL_SRCS = $(wildcard *.f *.for *.f90)
MODSRCS = $(filter mod_%,$(ALL_SRCS))
#MODSRCS = zmod.f
MODS := $(addsuffix .o, $(basename $(MODSRCS)))

SRCS = $(filter-out mod_%,$(ALL_SRCS))
#SRCS = sub1.f \
main.f90

OBJS := $(addsuffix .o, $(basename $(SRCS)))

TARGET = Program_N
#all:
#       @echo "ALL_SRCS=$(ALL_SRCS)"
#       @echo "OBJS=$(OBJS)"
#       @echo "MODS=$(MODS)"

$(TARGET): $(OBJS)
        $(FC) $(FFLAGS) -o $@ $(MODS) $(OBJS)

clean:
        rm -f $(TARGET) *.o *.mod

$(OBJS): $(MODS)

.SUFFIXES: .o .f .for .f90

.f.o:
        $(FC) $(FFLAGS) -c $<
.for.o:
        $(FC) $(FFLAGS) -c $<
.f90.o:
        $(FC) $(FFLAGS) -c $<

Ubuntu Linux 非root账户运行adb

在linux中,如果以非root账户运行adb命令通常回出现以下错误提示:

error: insufficient permissions for device

解决办法:给非root账户添加udev的写权限。操作如下。

添加/修改/etc/udev/rules.d/51-android.rules文件,之后重启udev服务。

对某特定品牌添加权限

#ZTE     19D2
SUBSYSTEM=="usb", ATTR{idVendor}=="19D2", MODE="0666"
#HTC 0bb4
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666"

或者你有很多的android设备,可以一次性解决

SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0666"




Host by is-Programmer.com | Power by Chito 1.3.3 beta | © 2007 LinuxGem | Design by Matthew "Agent Spork" McGee