正在加载...
分页: 1/6 第一页 1 2 3 4 5 6 下页 最后页 [ 显示模式: 摘要 | 列表 ]

shell grep 查找进程的小技巧

[ 2012/12/29 17:34 | by selboo ]
        大部分人在写Shell 过滤进程的时候  都会使用 grep  在 ps aux 的输出结果中查找指定的进程,但此时也会把 grep 进程也显示出来 比如查找 pptpd 进程,会匹配出来两条:

This is The Code
[root@selboo ~]# ps aux | grep pptp
root     20191  0.0  0.2   5108   704 pts/2    R+   16:58   0:00 grep pptp
root     22054  0.0  0.1   1952   608 ?        Ss   Oct22   0:00 /usr/sbin/pptpd
Parsed in 0.000 seconds at N/A

常见的防止grep进程出现的方法就是在对加一个管道 grep -v grep 进行过滤:

This is The Code
[root@selboo ~]# ps aux | grep pptp | grep -v grep
root     22054  0.0  0.1   1952   608 ?        Ss   Oct22   0:00 /usr/sbin/pptpd
Parsed in 0.000 seconds at N/A

还有一个更方便的方法是用 正则 grep [p]ptpd来搜索pptpd这个进程:

This is The Code
[root@selboo ~]# ps aux | grep [p]ptp  
root     22054  0.0  0.1   1952   608 ?        Ss   Oct22   0:00 /usr/sbin/pptpd
Parsed in 0.000 seconds at N/A

#!/bin/bash

SEND_THREAD_NUM=13
tmp_fifofile=”/tmp/$$.fifo” # 脚本运行的当前进程ID号作为文件名
mkfifo “$tmp_fifofile” # 新建一个随机fifo管道文件
exec 6<>”$tmp_fifofile” # 定义文件描述符6指向这个fifo管道文件
rm $tmp_fifofile
for ((i=0;i<$SEND_THREAD_NUM;i++));do
echo # for循环 往 fifo管道文件中写入13个空行
done >&6

for i in `seq 100`;do # 100 次 for 循环 开始
read -u6 # 从文件描述符6中读取行(实际指向fifo管道)

{
echo $i # 打印 i
sleep 3 # 暂停3秒
echo >&6 # 再次往fifo管道文件中写入一个空行。
} &

# {} 这部分语句被放
Tags: ,

linux shell快捷键

[ 2010/09/07 10:33 | by selboo ]
切到命令行开始|结尾
# Ctrl + A - Go to the beginning of the line you are currently typing on
# Ctrl + E - Go to the end of the line you are currently typing on

清屏,类似于 clear 命令
# Ctrl + L - Clears the Screen, similar to the clear command

清除光标以前
# Ctrl + U - Clears the line before the cursor position. If you are at the end of the line, clears the entire line.

退格键 backspace
# Ctrl + H - Same as backspace

从命令历史中找
# Ctrl + R - Let’s you search throug

shc 加密Shell 脚本

[ 2010/09/01 09:41 | by selboo ]
下载安装 shc
wget ftp://ftp.pbone.net/mirror/ftp.freshrpms.net/pub/freshrpms/pub/dag/redhat/el4/en/i386/RPMS.dag/shc-3.8.6-1.el4.rf.i386.rpm

加密Shell
[code][root@GameDB shc]# cat rsync.sh
#!/bin/bash
rsync -avz --delete 192.168.1.10::data /data/
[root@GameDB shc]# shc -rvf rsync.sh
shc shll=bash
shc [-i]=-c
shc [-x]=exec '%s' "$@"
shc [-l]=
shc opts=
shc: sh.x.c -o rsync.sh
Tags: ,

深入浅出Shell编程: Shell 变量

[ 2010/08/31 10:43 | by selboo ]





































表示方法描述
$n$1 表示第一个参数,$2 表示第二个参数 …
$#命令行参数的个数
$0当前程序的名称
$?前一个命令或函数的返回码
$*以”参数1 参数2 … ” 形式保存所有参数
$@以”参数1″ “参数2″ … 形式保存所有参数
$$本程序的(进程ID号)PID
$!上一个命令的PID
Tags:
分页: 1/6 第一页 1 2 3 4 5 6 下页 最后页 [ 显示模式: 摘要 | 列表 ]