bash scripts(3)
Example 5-4. Integer or string?#!/bin/bash # int-or-string.sh # Integer or string? a=2334 # Integer. let "a += 1" echo "a = $a " # Integer, still. echo b=${a/23/BB} # Transform into a string. echo "b = $b" # BB35 declare -i b # Declaring it an integer doesn't help. echo "b = $b" # BB35, still. let "b += 1" # BB35 + 1 = echo "b = $b"
bash scripts(4)
Example 5-2. Plain Variable Assignment#!/bin/bash echo # When is a variable "naked", i.e., lacking the '$' in front? # When it is being assigned, rather than referenced. # Assignment a=879 echo "The value of "a" is $a" # Assignment using 'let' let a=16+5 echo "The value of "a" is now $a" echo # In a 'for' loop (really, a type of disguised assignment) echo -n "The values of "a" in the loop are " for a i
bash scripts(2)
Example 3-1. exit / exit status#!/bin/bash echo hello echo $? # Exit status 0 returned because command successful. lskdf # Unrecognized command. echo $? # Non-zero exit status returned. echo exit 113 # Will return 113 to shell. # To verify this, type "echo $?" after script terminates. # By convention, an 'exit 0' indicates success, # while a non-zero exit value means an error or anomalous condition.Example 3-2. Negating a condition using !true # the &qu
bash scripts(1)
Example 2-1. cleanup: A script to clean up the log files in /var/log # cleanup # Run as root, of course. cd /var/log cat /dev/null > messages cat /dev/null > wtmp echo "Logs cleaned up."Example 2-2. cleanup: An enhanced and generalized version of above script.#!/bin/bash # cleanup, version 2 # Run as root, of course. LOG_DIR=/var/log ROOT_UID=0 # Only users with $UID 0 have root privileges. LINES=50 # Default number of lines saved. E_XCD=66 # Can't
Linux系统帐户的管理和审计
在Linux下登录用户帐户的管理是通过utmp和wtmp这两个工具来实现的。wtmp还记录系统重启和系统状态变化的有关信息。所有与utmp和wtmp相关的数据都分别被保存在/var/run/utmp.和/var/log/wtmp这两个文件中。这两个文件均归属于root用户所有并且访问权限被设置为644,这些文件中的数据是加密过的。可以用dump-utmp这个工具将原始的数据转换为ASCII的数据,便于系统管理员分析用户的登录以及系统重启和系统状态变化的有关信息。 登录帐户管理的相关命令 last 命令提供了每个用户登录和退出的时间,同时还有系统重新启动以及运行状态改变
bash条件判断
string判断 -z 判断是否空串 [ -z $test ]= 字符串相等 [ "$test1" = "$test2" ]!= 字符串不相等-n 非空串数值判断-eq 数值相等-ne 数值不相等-gt 第一个数大于第二个数-lt -le 小于等于-geexpr expr 10 + 10[@more@]
sed初级
sed其中p代表打印,没有p会出错误sed -n '2p' test.txt #显示第2行sed -n '1,3p' test.txt #显示第1到3行1.模糊匹配sed -n '/a/'p test.txt #使用模式符号// sed -n '3,/a/'p test.txt #只在第3行查询模式a sed -n '1,$p' test.txt #显示所有数据,$代表结尾要打印行号使用//=sed -e '/music/=' quote.txt[@more@]
awk初级
1.常规用法awk '{print $0,$1}' test.txtawk '{print $0"t"$1}' test.txtawk 'BEGIN {print "This is a simple test"} {print $1"t"$2}' test.txtawk 'BEGIN {print "Namen------"}{print $1} END{"end-of-report"}}'2.匹配模糊匹配:awk {if($4~/brown/) print $0}' grade.txt awk {if($4!~/brown/) print $0}' grade.txt精确匹配:awk {if($3==/48/) print $0}' grade.txt awk {if($3!=/48/) print $0}' grade.txtawk {if($4!~/brown/ ||$4=="hello") print $0}' grade.txt[
JMS心得
import org.springframework.jms.core.JmsTemplate;/** * the class use to receive the MQ message */public class JmsLogConsumer{ private JmsTemplate jmsTemplate; /** * @return Returns the jmsTemplate. */ public JmsTemplate getJmsTemplate() { return jmsTemplate; } /** * @param jmsTemplate The jmsTemplate to set. */ public void setJmsTemplate(JmsTemplate jmsTemplate) { this.jmsTemplate = jmsTemplate; } public Object receiveMessage() { return this.jmsTemplate.receiveAndConvert(); }}消费者rec
搜索接口总结
这次需求是采用2进制分别生成索引文件和数据文件,索引文件每次写21个字节,21个字节格式是固定的.数据文件里保存的是java对象,这里特别得注意,这个数据文件和索引文件最后都需要c程序修改的,最后我来解析:( 索引文件:long->bytes[],int->bytes[],偏移和长度必须正确.java中有read(bytes),每次读21个.数据文件采用的是RandomAccessFile,因为可以将文件指针移到开始,不必频繁打开数据流.移到开始只需要seek(0)就可以了.skipBytes(位移),然后read(bytes),最后oro正则解析.原来计算偏移用available后来发现不行,还是自己在写的时候就必
基础类型与字节数组相互转换函数
static long bytes2long(byte[] b) { //byte[] b=new byte[]{1,2,3,4}; long mask=0xff; long temp=0; long res=0; for(int i=0;i<8;i++){ res<<=8; temp=b[i]&mask; res|=temp; } return res; } static byte[] long2bytes(long num) { byte[] b=new byte[8]; for(int i=0;i<8;i++){ b[i]=(byte)(num>>>((7-i)*8))); } return b; } static int bytes2int(byte[] b){//byte[] b=new byte[]{1,2,3,4};int mask=0xff;int temp=0;int res=0;for(int i=0;i<4;i++){res<<=8;temp=b[i]&mask;res|=temp;}re
perl的一些常用函数
字符串函数uc将字符串转化成大写字母lc将字符串转化成小写字母chr根据ASCII返回某个字符length得到str得长度int将某常量转化成整数index返回索引号index($string,$lookfor)substr提取字符串substr($string,$offset,$length)字符串连接符号$a.$b连接字符串a,b$a x value 将字符串a重复value遍$a.=$b将b添加到a的末尾splice允许拼接数组.splice(@array,offset,length,$resplace,$replace)hash中的函数keys(%hash)values(%hash)delete $hash{"names"}exists $hash{"name"}%ENV返回当前系统的所有变量@ARGV返回命令行参数