寻觅生命中的那一片浅草......

文章带标签 Linux

史上最强bash函数库

多为系统操作相关,如

取内网地址: get_localip()
取内网网口: get_local_iface()
取网关的IP:  get_gateway_ip()
添加一个cron作业: add_cron()
删除一个cron作业: del_cron()
取内存大小: get_mem_size()
取硬盘大小: get_hdd_size()
查找非系统默认帐号:find_non_sys_user()
………

使用方法:
将func-common.sh和主脚本放在同一个目录下
在主脚本中source函数库后直调用, 函数参数见注释说明
复制内容到剪贴板
代码:

export WORKDIR=$( cd ` dirname $0 ` && pwd )

if [[ ! -r “$WORKDIR/func-common.sh” ]]; then
echo “[$WORKDIR/func-common.sh] NOT FOUND”
exit 1
fi

. “$WORKDIR/func-common.sh” || exit 1
代码存于google svn中, 会不定期更新
http://huan.googlecode.com/svn/bash/func-common.sh

转载自:http://bbs.linuxeden.com/thread-192227-1-1.html

redhat的rpc.statd服务

共享和加载NFS文件系统需要什么服务?
解决方法:红帽企业Linux使用核心级的支持和守护进程的组合来提供NFS文件共享.NFS依靠远程过程调用(RPC)在客户端和服务器端路由请求。在Linux下RPC服务由portmap服务控制.

为了共享和加载NFS文件系统,下面的服务要一起工作:

* nfs – 启动相应RPC服务进程来服务对于NFS文件系统的请求.
* nfslock – 一个可选的服务,用于启动相应的RPC进程,允许NFS客户端在服务器上对文件加锁.
* portmap – Linux的RPC服务,它响应RPC服务的请求和与请求的RPC服务建立连接.

下面的RPC进程在后台一起工作服务于NFS服务:

* rpc.mountd – 这个进程接受来自NFS客户端的加载请求和验证请求的文件系统正在被输出.这个进程由NFS服务自动启动,不需要用户的配置.

* rpc.nfsd – 这个进程是NFS服务器.它和Linux核心一起工作来满足NFS客户端的动态需求,例如提供为每个NFS客户端的每次请求服务器线程.这个进程对应于nfs服务.

* rpc.lockd – 一个可选的进程,它允许NFS客户端在服务器上对文件加锁.这个进程对应于nfslock服务.

* rpc.statd – 这个进程实现了网络状态监控(NSM)RPC协议,通知NFS客户端什么时候一个NFS服务器非正常重启动.这个进程被nfslock服务自动启动,不需要用户的配置.

* rpc.rquotad – 这个进程对于远程用户提供用户配额信息. 这个进程被nfs服务自动启动,不需要用户的配置.

停用命令

service nfslock stop

chkconfig nfslock off

rpcbind服务停止命令

service portmap stop

转载自:http://falchion.javaeye.com/blog/400132

rsync error: error in rsync protocol data stream

今天去检查备份文件,发现有台服务器的文件没有同步过来
手动同步一下,报以下错误

rsync: connection unexpectedly closed (0 bytes received so far) [receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(359)

试过以下方法,都不可以
重启rsync
重装rsync
查看rsync的密码文件,没有错

最后服务器上看
netstat -tlnp
发现监听873端口的变成了rpc.statd,而不是rsync
tcp        0      0 0.0.0.0:873                 0.0.0.0:*                   LISTEN      3659/rpc.statd

晚上搜索了,知道这是nfslock的进程,马上
service portmap stop
service nfs stop
service nfslock stop

chkconfig –level 2345 portmap off
chkconfig –level 2345 nfslock off
chkconfig –level 2345 nfs off

再开启
/usr/local/bin/rsync –daemon

此时同步,终于成功了

CentOS5.3_64位编译PHP出错

64位的系统给php添加curl的时候,
cd /usr/local/src/php-5.2.6/ext/curl/
/usr/local/php-fcgi/bin/phpize
./configure –with-php-config=/usr/local/php-fcgi/bin/php-config
居然出现一下错误!
checking for gnutls support in libcurl… no
checking for curl_easy_perform in -lcurl… no
configure: error: There is something wrong. Please check config.log for more information.

我赶紧检查有没有装curl的devel
rpm -qa |grep curl

全都有!
查了半天资料, 还是找到结果了, 只要以下包都安装了, 就可以完美通过!
curl-devel-7.15.5-2.el5
e2fsprogs-devel-1.39-15.el5
krb5-devel-1.6.1-25.el5
libidn-devel-0.6.5-1.1
openssl-devel-0.9.8b-10.el5
至于每个包的作用, 自己去查吧! 呵呵

转载自:

http://www.linuxquestions.org/questions/linux-software-2/install-php-on-a-64bit-centos-problem.-help.-673530/

SysAdmin to SysAdmin:bring out your inner xargs

xargs is your friend. Using xargs, you can pull off feats of greatness and not have to write a script to do it. xargs can take care of things right on the command line. Though I focus mainly on files in this article (it’s what I use it for almost exclusively), it’s important to remember that xargs acts on standard input, which could mean lines redirected from /var/log/messages or urls or whatever else you can manage to point in its direction.

One of the things I use xargs for in the course of my work is package management. My department standardized on Red Hat for all Linux boxes, which means I use RPM a lot. Sometimes, though, RPM isn’t the most wonderful tool in the world to deal with. One thing that makes RPM nice, though, is that it can take flags, file arguments and options in any order (for the things I’m using it for anyway). Let’s look at an example scenario you can use even if you’re not working with centralized software management in a mid-size network:

I’m a huge fan of Galeon. Back when they released 1.0.2, I had to have it. Unfortunately, my Ximian installation put packages tagged with their name on my system, and the Galeon RPM didn’t recognize them, which created dependency errors. <whine> “I can’t find mozilla-0.9.7″</whine>.

Having had some issues on my workstation at the office (it works fine on two other machines), I decided to uninstall any trace of Mozilla, and get standard Mozilla packages. But I don’t have a lot of time to do this stuff, so here’s what I did:

$ > rpm -qa | grep mozilla | xargs -n1 -p rpm -e –nodeps

What this says in English, is “Using RPM, query all (-qa) packages, look for mozilla in the package name, and send the results one at a time (-n1), to RPM’s uninstall command, and I don’t care about dependencies, thank you very much (“rpm -e –nodeps”). Also, in case there’s something that contains the word “mozilla” that I DON’T want erased, prompt me (-p) before uninstalling.”

The above command saves you from having to manually list the packages containing the string “mozilla,” then manually running separate “rpm -e” commands against them one at a time.

How about something REALLY useful! I rip CDs constantly using grip. Inevitably, I’ll reinstall and forget to not format the /mp3 partition, or I’ll upgrade grip and forget to change the directories it uses to store stuff… whatever. Eventually, I have MP3s all over my hard drive. What I do then is this:

$ > find / -name *.mp3 -type f -print | xargs tar -cvzf mp3z.tar.gz

This finds all the mp3z on my entire drive and puts ’em all in a tar file, and then I can untar them wherever I want :) I actually could’ve piped that xargs “tar” line into a “tar xvzf” line to automatically untar them. I also could’ve left out the “-type f” if I had grip set up to use a custom directory structure that I wanted to preserve. You get the idea :) PS – this works for other types of files, too, like finding all the files that belong to you, tarring them and sending the tar to a backup somewhere, so it does have legitimate use.

Ok, so this is good for stuff that takes the file name or other argument as the last thing on the line – but what about things like “cp,” that take an argument, and then another piece of input like a directory to copy to or a file to copy over or something? That’s where the ‘-i’ flag comes in. This flag allows you to specify some string that will then be replaced with the arguments you send to xargs in place. Expanding on the “cp” example:

$> ls *.mp3 | xargs -n1 -i cp {} backup/.

This command takes all of the MP3 files in the current directory, and feeds them one at a time (-n1) to the cp command, where the file argument coming in from ls will replace the curly braces. Notice I didn’t specify a string with “-i.” I don’t think I’ve ever had to. The default string that xargs will look to replace when using the -i flag is the curly braces.

As your command lines get a little more complex, or you start using xargs in scripts, there are a couple of useful troubleshooting flags you may find helpful if you run into issues. One, the -p flag, will prompt you for a yes or no before executing a command on anything. The other, which is a real life saver, is “-t,” and it does NOT prompt you for a yes or no (unless you use it with -p), but it will output the command it’s trying to execute, so if something isn’t quite right, you’ll be able to spot it right away.

转载自:http://www.linux.com/archive/feature/113662

2025年六月
« 5月    
 1
2345678
9101112131415
16171819202122
23242526272829
30