存档

文章标签 ‘linux’

如何创建动态MOTD

2011年9月10日 没有评论

背景介绍

刚到淘宝时发现很多服务器登陆后都会显示一段AsciiArt的信息,觉得很好玩,也稍微有点用。如果你关心具体是什么,可以发送简历到jinxi.kj@taobao.com:)

如何显示静态MOTD

以上是背景,上网搜了一下,找到了相关的资料。其实很简单,只要修改了/etc/motd文件,登陆时就会被显示出来。如果需要增加颜色的话,可以参照这里的方法:“So You Like Color–The Mysterious ^[[ Characters" (http://www.linuxjournal.com/article/8603)。在vim中输入Ctrl+V后再按ESC,接下来写上颜色代码就行。有玩过term bbs的话应该会很熟悉。

如何显示动态MOTD

设置好/etc/motd后,马上就发现了一个问题,这是个静态的内容,自然就不能显示动态的信息。比如ip地址、硬盘占用、进程数等,除此之外,也没人喜欢部署多台机器时手动在motd中设置机器相关的参数,比如CPU、core数等。于是我就找到了这篇Blog: "HOWTO: Creating a Dynamic MOTD in Linux" (http://parkersamp.com/2010/10/howto-creating-a-dynamic-motd-in-linux/)。

具体方法很简单,编写一个脚本显示动态的motd,然后添加到/etc/profile中执行就行了。当然还需要禁用/etc/motd的显示。

如何禁用静态MOTD

修改: /etc/ssh/sshd_config
PrintMotd no
然后重启sshd: /etc/init.d/sshd restart or service sshd restart
更多信息参考上面提到的Blog。当然,最简单最暴力的方法是把/etc/motd文件中内容清空。

如何安装动态MOTD脚本

1. 将动态MOTD脚本放到某个目录下,比如/usr/local/bin/dynmotd。
2. 将脚本添加到/etc/profile中
修改: /etc/profile
/usr/local/bin/dynmotd

我自定义的Python脚本

由于前面我找到的Blog中使用的脚本是shell导致不方便修改,而且部分信息还是写死的;另一方面,Mac下面不能完全兼容。所以我自己用Python实现了一个类似的脚本,支持MacOS与Linux。考虑到不想把这个简单脚本搞得太复杂,所以没有用到兼容性、全面性更好地psutil。有兴趣的可以自己试试。

脚本可以到这里获取: https://github.com/chzealot/tools/tree/master/python/dynmotd

显示效果

MacOS(Darwin)下的显示效果

MacOS(Darwin)下的显示效果

Linux下的显示效果

Linux下的显示效果

R61在linux/debian下安装madwifi无线驱动

2010年4月6日 没有评论

本文记录Thinkpad R61i在debian lenny下安装madwifi驱动程序,替代ath5k,实现无线上网。
主要参考:http://forum.ubuntu.org.cn/viewtopic.php?f=116&t=169205。
仅作为tp安装linux的备忘,欢迎评论。

1. 下载
   Download the latest madwifi snapshot. // Google it

2. 解压
   $ tar zxvf madwifi-hal-0.10.5.6-current.tar.gz

3. 编译安装madwifi // 首先通过apt安装编译环境
   $ sudo aptitude install build-essential linux-headers-$(uname -r)
   $ make
   $ sudo make install

4. 安装module
   $ sudo modprobe ath_pci

5. 使网卡每次开机时都加载, make it load every time you boot
   $ sudo vi /etc/modules
   添加一行,如下
     ath_pci

6. 重新启动机器
   $ sudo reboot

注释 && 备忘
1. 为保证生效,重启前确认已屏蔽ath5k(默认驱动程序有可能是这个)
   检查是否已安装ath5k
   $ lsmod |grep ath5k
   有,则添加到blacklist
   $ cat /etc/modprobe.d/blacklist.conf
     blacklist ath5k
2. 确认安装驱动是否成功
   $ lsmod | grep ath_pci
     ath_pci               201176  0
     wlan                  193392  5 wlan_wep,wlan_scan_sta,ath_rate_sample,ath_pci
     ath_hal               300768  3 ath_rate_sample,ath_pci
3. 硬件型号查看
   $ lspci |grep Ethernet
     00:19.0 Ethernet controller: Intel Corporation 82566MM Gigabit Network Connection (rev 03)
     03:00.0 Ethernet controller: Atheros Communications Inc. AR242x 802.11abg Wireless PCI Express Adapter (rev 01)
4. ath5k是madwifi替代品,除非ath5k下无法连接无线,不建议使用madwifi

Linux/Debian字体去掉锯齿的方法

2009年10月21日 没有评论

Linux/Debian字体去掉锯齿的方法

在台式机上装了个Debian,但不知道怎么设置字体清晰,网上找了很多方法,都不好使,一直都很模
糊地讲究着。不过把字号稍微设置大点就不模糊了,浏览网页和用terminal都没问题,只是菜单栏地
址栏什么的基本看不清楚。
今天突然上网搜了一下,看到这个词antialias,突然想起来我没改过这个。赶紧看看~/.fonts.conf
。果然,里面antialias设为false,这个应该是反锯齿选项,设为true:
<edit mode=”assign” name=”antialias” >
<bool>true</bool>
</edit>
然后ctrl+alt+backspace重启x,菜单栏小字体都清晰了,Great,哈哈:-)
上两张图

在台式机上装了个Debian,但不知道怎么设置字体清晰,网上找了很多方法,都不好使,一直都很模

糊地将就着。不过把字号稍微设置大点就不模糊了,浏览网页和用terminal都没问题,只是菜单栏地

址栏什么的基本看不清楚。

今天突然上网搜了一下,看到这个词antialias,突然想起来我没改过这个。赶紧看看~/.fonts.conf

。果然,里面antialias设为false,这个应该是反锯齿选项,设为true:

<edit mode=”assign” name=”antialias” >

<bool>true</bool>

</edit>

然后ctrl+alt+backspace重启x,菜单栏小字体都清晰了,Great,哈哈:-)

上几张图看看

1. 桌面的菜单 – 有锯齿,很模糊

menu turn off antialias

menu turn off antialias

2. 再看看打开反锯齿功能后的菜单

开启反锯齿效果的菜单

开启反锯齿效果的菜单

3. firefox:取消反锯齿的firefox看小字体的文字没法用,大字体还好,每次都得ctrl++来放大字体

取消反锯齿的firefox,太模糊了

取消反锯齿的firefox,太模糊了

4. 在看一下开启反锯齿效果后的firefox

开启反锯齿效果后的firefox

开启反锯齿效果后的firefox

解决apt-get中依赖的库无法安装的问题

2009年4月28日 没有评论

今天apt-get install vim-full的时候,出现了错误,详见后面。原因不清楚,估计是sun-java5-jre这个包相关的东西出了问题,彻底清除了试试:sudo apt-get –purge remove sun-java5-jre,然后重新装上。。
再来sudo apt-get install vim-full,OK。

Reading package lists…
Building dependency tree…
You might want to run `apt-get -f install’ to correct these:
The following packages have unmet dependencies:
sun-java5-jre: Depends: sun-java5-bin (= 1.5.0-14-1etch1) but it is not going to be installed or
ia32-sun-java5-bin (= 1.5.0-14-1etch1) but it is not installable
vim-full: Depends: vim-gui-common (= 1:7.0-122+1etch5) but it is not going to be installed
Depends: vim-common (= 1:7.0-122+1etch5) but 1:7.0-122+1etch3 is to be installed
Depends: vim-runtime (= 1:7.0-122+1etch5) but 1:7.0-122+1etch3 is to be installed
Depends: libart-2.0-2 (>= 2.3.16) but it is not going to be installed
Depends: libatk1.0-0 (>= 1.12.2) but it is not going to be installed
Depends: libbonobo2-0 (>= 2.13.0) but it is not going to be installed
Depends: libbonoboui2-0 (>= 2.5.4) but it is not going to be installed
Depends: libcairo2 (>= 1.2.4) but it is not going to be installed
Depends: libgconf2-4 (>= 2.13.5) but it is not going to be installed
Depends: libglib2.0-0 (>= 2.12.0) but it is not going to be installed
Depends: libgnome-keyring0 (>= 0.6.0) but it is not going to be installed
Depends: libgnome2-0 (>= 2.14.1) but it is not going to be installed
Depends: libgnomecanvas2-0 (>= 2.11.1) but it is not going to be installed
Depends: libgnomeui-0 (>= 2.13.0) but it is not going to be installed
Depends: libgnomevfs2-0 (>= 2.13.92) but it is not going to be installed
Depends: libgtk2.0-0 (>= 2.8.0) but it is not going to be installed
Depends: liborbit2 (>= 1:2.14.1) but it is not going to be installed
Depends: libpango1.0-0 (>= 1.14.8) but it is not going to be installed
Depends: libperl5.8 (>= 5.8.8) but it is not going to be installed
Depends: libruby1.8 (>= 1.8.5) but it is not going to be installed
Depends: libxcursor1 (> 1.1.2) but it is not going to be installed
Depends: libxfixes3 (>= 1:4.0.1) but it is not going to be installed
Depends: libxi6 but it is not going to be installed
Depends: libxinerama1 but it is not going to be installed
Depends: libxrandr2 but it is not going to be installed
Depends: libxrender1 but it is not going to be installed
Depends: tcl8.4 (>= 8.4.5) but it is not going to be installed

Linux 入门:阅读man手册

2008年10月30日 没有评论

From : http://www.fire3.cn/2008/08/03/linux-howto-read-man-page.html

 
 

搜索和打印介绍不错:)

 
 

1 什么是man手册

 
 

首先,man是manual的简称,中文说法可以是手册。

 
 

在Linux世界中,许多新手请教某条命令的用法时, 好多不耐心的老手通常会用一条命令来回答这位无助的新手,而这条命令通常

就是man开头。无助的新手敲上这条命令一看究竟,在终端上顿时显示出来了一屏幕的英文,

老手的意思是,自己看看手册吗,可是看手册也是有学问的,无助的新手甚

至不知道怎么退出这条命令呢。下面我们就来讲解一下看man手册的学问。

2 从man手册中获取有用的信息

 
 

我们先以mkdir命令来解释读man手册的一些入门知识。

 
 

MKDIR(1) User Commands MKDIR(1)

 
 

NAME

mkdir – make directories

 
 

SYNOPSIS

mkdir [OPTION] DIRECTORY…

 
 

DESCRIPTION

Create the DIRECTORY(ies), if they do not already exist.

 
 

Mandatory arguments to long options are mandatory for short options too.

 
 

-m, –mode=MODE

set file mode (as in chmod), not a=rwx – umask

 
 

-p, –parents

no error if existing, make parent directories as needed

 
 

-v, –verbose

print a message for each created directory

 
 

-Z, –context=CTX

set the SELinux security context of each created directory to CTX

 
 

–help display this help and exit

 
 

–version

output version information and exit

 
 

AUTHOR

Written by David MacKenzie.

 
 

REPORTING BUGS

Report bugs to <bug-coreutils@gnu.org>.

 
 

COPYRIGHT

Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

 
 

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

 
 

SEE ALSO

 
 

mkdir(2)

 
 

The full documentation for mkdir is maintained as a Texinfo manual. If the info and mkdir programs are properly installed at your site, the com-

 
 

mand

 
 

info coreutils ‘mkdir invocation’

 
 

should give you access to the complete manual.

 
 

首先第一行 MKDIR(1),显然,MKDIR是命令的大写,那么为什么有个(1)呢,那是因为man手册页有如下的规定:

Section         名称         说明

l         本地文档         与本特定系统有关的

1         用户命令         可由任何人启动的

2         系统调用         即由内核提供的函数

3         例程         即库函数

4         设备         即/dev目录下的特殊文件

5         文件格式描述         例如/etc/passwd

6         游戏         不用解释啦

7         杂项         例如宏命令包、惯例等

8         系统管理员工具         只能由root启动

9         其他(Linux特定的)         用来存放内核例行程序的文档

n         新文档         可能要移到更适合的领域

o         老文档         可能会在一段期限内保留

 
 

MKDIR(1)表示该命令属于Section 1,为用户命令,类似的man

apt-get会看到APT-GET(8),表示apt-get命令为系统管理工具。

 
 

“NAME”部分是该命令的名字和简单的解释,显然,在命令行中要执行该命令要使用到它的名称。

 
 

“SNOPSIS”是摘要部分,简要解释该命令如何使用,比如mkdir的摘要:

mkdir [OPTION] DIRECTORY…,读到这里便需要讲解一下了:

 
 

“OPTIONS”左右有”["和"]“,表示这些参数并不必须,但是可以使用。对应的DIRECTORY两边没有”[]“,就是必须要加的参数了。

另外,它们后面都有”…” ,表示这些参数可以重复使用多次。至于OPTIONS具体怎么用,就要看DESCRIPTION部分了。下面举几个简单的例子,并配合例子解释:

用法         解释

mkdir tmp         创建 tmp 目录

mkdir –mode=a+w tmp         创建一个模式为”a+w”的tmp目录,–mode是长参数,用法是–mode=MODE,在DESCRIPTION里说明

mkdir -m a+w tmp         创建一个模式为”a+w”的tmp目录,-m 是短参数,不用加 = 号,效果等同 –mode=MODE

mkdir -mv a+w tmp         创建一个模式为”a+w”的tmp目录,同时显示信息,verbose模式,-mv可以一起用

mkdir -v -m a+w tmp         创建一个模式为”a+w”的tmp目录,同时显示信息,verbose模式,-v后面接一个空格再用-m

3 man手册页的操作

3.1 退出man

 
 

最简单,按下”q”键

3.2 查找

 
 

如果你知道要打开的手册页,在man命令打开的手册页中可以用

“/” 键进行正则表达式的搜索。

 
 

如果不知道所要打开的手册页名称,可以用 “man

-k”命令搜索相关的手册页,比如:

 
 

man -k postscript

 
 

会给出一堆关于”postscript”的相关命令页。

3.3 打印

 
 

最简单的办法,以mkdir为例:

 
 

man -t mkdir > mkdir_man.ps

 
 

可以直接打印ps,打算发给别人打印的话,转换成pdf也比较方便:

 
 

ps2pdf mkdir_man.ps mkdir_man.pdf

分类: linux 标签: , , , , ,

Squid安装、配置和使用

2008年10月8日 没有评论

  • 获取Squid
  • 编译安装
  • 快速配置
  • 运行Squid
分类: linux 标签: , , ,

chmod 命令

2008年8月6日 没有评论

这个命令用的比较多了,作用很简单:改变文件的权限

平时主要能涉及到的就读写执行三种权限了,分别对应rwx

主要形式用的比较多的就是:”chmod 三个数字表示权限 文件” 和 “chomd a+x 文件”,其中a表示所有用户,还有u,g,加好增加相应权限,减号相反。目录的执行权限定义不一样。

详细介绍如下:

http://blog.csdn.net/chenshaoying/archive/2008/08/04/2767064.aspx

chmod用于改变文件或目录的访问权限。用户用它控制文件或目录的访问权限。该命令有两种用法。一种是包含字母和操作符表达式的文字设定法;另一种是包含数字的数字设定法。

1. 文字设定法

语法:chmod [who] [+ | - | =] [mode] 文件名

命令中各选项的含义为:

操作对象who可是下述字母中的任一个或者它们的组合:
  u 表示“用户(user)”,即文件或目录的所有者。
  g 表示“同组(group)用户”,即与文件属主有相同组ID的所有用户。
  o 表示“其他(others)用户”。
  a 表示“所有(all)用户”。它是系统默认值。
操作符号可以是:
  + 添加某个权限。
  - 取消某个权限。
  = 赋予给定权限并取消其他所有权限(如果有的话)。
设置 mode 所表示的权限可用下述字母的任意组合:
  r 可读。
  w 可写。
   x 可执行。
  X 只有目标文件对某些用户是可执行的或该目标文件是目录时才追加x 属性。
  s 在文件执行时把进程的属主或组ID置为该文件的文件属主。
      方式“u+s”设置文件的用户ID位,“g+s”设置组ID位。
  t 保存程序的文本到交换设备上。
  u 与文件属主拥有一样的权限。
  g 与和文件属主同组的用户拥有一样的权限。
  o 与其他用户拥有一样的权限。
文件名:以空格分开的要改变权限的文件列表,支持通配符。

在一个命令行中可给出多个权限方式,其间用逗号隔开。例如:

chmod g+r,o+r example  % 使同组和其他用户对文件example 有读权限。

2. 数字设定法

我们必须首先了解用数字表示的属性的含义:0表示没有权限,1表示可执行权限, 2表示可写权限,4表示可读权限,然后将其相加。所以数字属性的格式应为3个从0到7的八进制数,其顺序是(u)(g)(o)。

例如,如果想让某个文件的属主有“读/写”二种权限,需要把4(可读)+2(可写)=6(读/写)。

数字设定法的一般形式为:

语法:chmod [mode] 文件名

指令实例:

chmod a+x sort
% 即设定文件sort的属性为:
 文件属主(u) 增加执行权限
 与文件属主同组用户(g) 增加执行权限
 其他用户(o) 增加执行权限

chmod ug+w,o-x text
% 即设定文件text的属性为:
 文件属主(u) 增加写权限
 与文件属主同组用户(g) 增加写权限
 其他用户(o) 删除执行权限

chmod u+s a.out
% 假设执行chmod后a.out的权限为(可以用ls – l a.out命令来看):
 –rws--x--x 1 inin users 7192 Nov 4 14:22 a.out
 并且这个执行文件要用到一个文本文件shiyan1.c,其文件存取权限为“–rw-------”,
  即该文件只有其属主具有读写权限。
   当其他用户执行a.out这个程序时,他的身份因这个程序暂时变成inin(由于chmod
  命令中使用了s选项),所以他就能够读取shiyan1.c这个文件(虽然这个文件被设定为
  其他人不具备任何权限),这就是s的功能。
  因此,在整个系统中特别是root本身,最好不要过多的设置这种类型的文件(除非
  必要)这样可以保障系统的安全,避免因为某些程序的bug而使系统遭到入侵。

chmod a–x mm.txt
chmod –x mm.txt
chmod ugo–x mm.txt
% 以上这三个命令都是将文件mm.txt的执行权限删除,它设定的对象为所有使用者。

$ chmod 644 mm.txt
% 即设定文件mm.txt的属性为:-rw-r--r--
 文件属主(u)inin 拥有读、写权限
 与文件属主同组人用户(g) 拥有读权限
 其他人(o) 拥有读权限

chmod 750 wch.txt
% 即设定wchtxt这个文件的属性为:-rwxr-x---
 文件主本人(u)inin 可读/可写/可执行权
 与文件主同组人(g) 可读/可执行权
 其他人(o) 没有任何权限
分类: linux 标签: , , ,