Archive for the ‘Shell编程’ Category

[Shell编程] SHELL中如何获得管道前面的命令的返回值

2015.9 1

To know the exit status of the elements of a pipeline cmd1 | cmd2 | cmd3 bash The exit codes are provided in the PIPESTATUS special array. cmd1 exit code is in ${PIPESTATUS[0]}, cmd3 exit code in … Read the rest of this entry

[Shell编程] awk 输出单引号双引号

2015.9 1

输出双引号 双引号中加反斜杠再加引号。 awk ‘{print “\””}’ 输出单引号:双引号中加双单引号,中间再加 反斜杠和单引号 awk ‘{print ” ‘ \’ ‘ “}’ Read the rest of this entry

[Shell编程] shell脚本改变工作目录

2015.2 2

shell脚本运行的几种方式: 1:添加脚本的执行权限,然后通过路径加文件名的方式运行 chmod +x test.sh;./test.sh 2:source test.sh 或者 . test.sh 3: sh test.sh 后两种方式不必添加脚本的执行权限。怎么改变shell脚本运行的工作目录呢?请看 Read the rest of this entry

[Linux] expect

2009.7 28

在写一些shell脚本的时候,经常会遇到需要用户输入密码的交互情况。 例如在用rsync备份的时候,如果没有假设rsync服务器端,需要用到ssh+rsync备份,没有提供输入密码的选项。上网上查了一下,有个expct的交互程序。 expect也够 Read the rest of this entry

[Shell编程] Shell 笔记

2009.7 12

1:保存命令的结果 $(ls -l /) 或者 `ls -l /` 2:判断 [[]] 与 [] [ -z $(ls -l /)] 或者 test 一个目录是否为空: [[ -z $(ls /a)]]||&&echo empty|| echo “not empty” 3:$(()) 算数运算 VAR=1 VAR=$(($VAR+1)) echo $VAR 4:while 循… Read the rest of this entry

[Shell编程] 字符编码转换的脚本

2009.7 8

程序中遇到汉字真是麻烦,弄的程序原本是gbk或者是gb2312的。现在服务器上都是utf-8,汉字全是乱码。只好写个shell,来自动转换。 2063cf48312ac54dded59e79c0a0f91c002 有两个难点,就是在判断是不是文本文件还有原来的编码的问题。先 Read the rest of this entry

[Shell编程] shell 参数替换

2009.7 2

今天在分析一个shell脚本的时候遇到了一个变量 ${2:15}。经我查阅shell经典参考书ABS后,得到如下解释: ${var:pos} 变量从位置pos开始扩展。 说得很抽象,我就自己弄了个例子: 2063cf48312ac54dded59e79c0a0f91c003 结果一目了然,就是取某 Read the rest of this entry

[Shell编程] 我要自己动手做个网站

2009.6 23

我要自己做个网站,用shell scripts写cgi程序。 先记录下cgi的环境变量 CGI Environment Variables Environment variables are a series of hidden values that the web server sends to every CGI program you run. Your program can … Read the rest of this entry

[Linux] 山东地区手机号的余额

2009.5 25

从山东移动的官方网站上充值的时候,会提示你的余额还有多少。不管手机号是谁的,只要是山东的号就行。因此想到通过curl提交一个这个表单,来查询某个手机号的余额。 通过查看提交手机号的表单,有几个是隐藏的控件。 Read the rest of this entry

[Linux] curl

2009.5 15

Linux 下的这些小工具实在是太有用了。一个个顺手的工具,用shell脚本连接起来就是个强大的工具。 curl,居然可以模拟浏览器。 -b/–cookie   发送保存的cookie给浏览器。 -c/–cookie-jar 保存浏览器发给的cookie。 #curl -c cookie Read the rest of this entry