Tag: Summary

  • “每天”打败一切

    有很多人说,每天要背一个单词。 这一句为本文第一句

    构思这篇博文已经很久了,每天做一些事,就那么难么

    不光是每天做一些好事,每天去克制去做一些不好的事,也是相当难

    今天写写自已对“每天”的看法

    有些事实我们不得不注意,每天的时间呢

    )每天看电视却不注意休息,得了近视

    )每天抽烟,得了癌症

    )每天晚睡早起,过劳致死

    )每天冷眼待人,到关键时无人出手帮忙

    )每天像机器一样坐公交上班下班,忙到一辈子也没什么出路

    换点好听的,积极的

    )每天看书思考,成为了思想家、教授、有钱人、有势力的人

    )每天发几个PT种子,PT变的越来越火

    )每天煅炼,活到人家骂你老不死

    )每天少抽一根烟

    )每天和家人通通电话

    )每天让阳光晒晒自已,浇浇花

    每天所做的事,可能造就你,也可能毁掉你

    我还是想不通,很多事里面的关系

    但是有一点我知道,有好“每天”,也有坏“每天”

    好“每天”就=自觉 坚持

    坏“每天”就=随落 享乐

    因为达到坏“每天”的标准太简单以至于不用去努力,人人原意做

    比如:每天看电视剧,看电影,上网,看有意思的视频

    这些东西,不用努力,轻轻松松,一个月也很容易算下来看了多少部电视剧和电影,小说,抽了多少烟,上了多少小时网,游戏多少级了,睡了多少个小时。。

    里面好像出了点问题

    出了什么问题?

    思想水平,智力水平,银行卡的数字,说话与谈吐 还是一个样,这还不说身体变差、视力变弱

    而“每天”搞了多少代码、看了多少书,做了多少笔记,这些就没那么简单了

    就像开头说的,每天背一个单词,就那么难么,不见得,就我对别人观察和对自已的分析,有几种想法

    )这几天不背了,过几天一起背

    )今天背十个单词,过几天不背了

    )每天背一个单词这件事太小不值的我背

    这种拖延、急功近利、忽视等的原因,被”每天“所打败

    而每天按自已要求做了,就一定能打败一切

  • HTTP常见状态码 400/401/403/404/500及更多

    HTTP 错误 400
    400 请求出错
    由于语法格式有误,服务器无法理解此请求。不作修改,客户程序就无法重复此请求。

    HTTP 错误 401
    401.1 未授权:登录失败
    此错误表明传输给服务器的证书与登录服务器所需的证书不匹配。
    请与 Web 服务器的管理员联系,以确认您是否具有访问所请求资源的权限。
    401.2 未授权:服务器的配置导致登录失败
    此错误表明传输给服务器的证书与登录服务器所需的证书不匹配。此错误通常由未发送正确的 WWW 验证表头字段所致。
    请与 Web 服务器的管理员联系,以确认您是否具有访问所请求资源的权限。
    401.3 未授权:由于资源中的 ACL 而未授权
    此错误表明客户所传输的证书没有对服务器中特定资源的访问权限。此资源可能是客户机中的地址行所列出的网页或文件,也可能是处理客户机中的地址行所列出的文件所需服务器上的其他文件。
    请记录试图访问的完整地址,并与 Web 服务器的管理员联系以确认您是否具有访问所请求资源的权限。
    401.4 未授权:授权服务被筛选程序拒绝
    此错误表明 Web 服务器已经安装了筛选程序,用以验证连接到服务器的用户。此筛选程序拒绝连接到此服务器的真品证书的访问。
    请记录试图访问的完整地址,并与 Web 服务器的管理员联系以确认您是否具有访问所请求资源的权限。
    401.5 未授权:ISAPI/CGI 应用程序的授权失败
    此错误表明试图使用的 Web服务器中的地址已经安装了 ISAPI 或 CGI程序,在继续之前用以验证用户的证书。此程序拒绝用来连接到服务器的真品证书的访问。
    请记录试图访问的完整地址,并与 Web服务器的管理员联系以确认您是否具有访问所请求资源的权限

    HTTP 错误 403
    403.1 禁止:禁止执行访问
    如果从并不允许执行程序的目录中执行 CGI、ISAPI或其他执行程序就可能引起此错误。
    如果问题依然存在,请与 Web 服务器的管理员联系。
    403.2 禁止:禁止读取访问
    如果没有可用的默认网页或未启用此目录的目录浏览,或者试图显示驻留在只标记为执行或脚本权限的目录中的HTML 页时就会导致此错误。
    如果问题依然存在,请与 Web 服务器的管理员联系。
    403.3 禁止:禁止写访问
    如果试图上载或修改不允许写访问的目录中的文件,就会导致此问题。
    如果问题依然存在,请与 Web服务器的管理员联系。
    403.4 禁止:需要 SSL
    此错误表明试图访问的网页受安全套接字层(SSL)的保护。要查看,必须在试图访问的地址前输入https:// 以启用 SSL。
    如果问题依然存在,请与 Web服务器的管理员联系。
    403.5 禁止:需要 SSL 128
    此错误消息表明您试图访问的资源受 128位的安全套接字层(SSL)保护。要查看此资源,需要有支持此SSL 层的浏览器。
    请确认浏览器是否支持 128 位 SSL安全性。如果支持,就与 Web服务器的管理员联系,并报告问题。
    403.6 禁止:拒绝 IP 地址
    如果服务器含有不允许访问此站点的 IP地址列表,并且您正使用的 IP地址在此列表中,就会导致此问题。
    如果问题依然存在,请与 Web服务器的管理员联系。
    403.7 禁止:需要用户证书
    当试图访问的资源要求浏览器具有服务器可识别的用户安全套接字层(SSL)证书时就会导致此问题。可用来验证您是否为此资源的合法用户。
    请与 Web服务器的管理员联系以获取有效的用户证书。
    403.8 禁止:禁止站点访问
    如果 Web服务器不为请求提供服务,或您没有连接到此站点的权限时,就会导致此问题。
    请与 Web 服务器的管理员联系。
    403.9 禁止访问:所连接的用户太多
    如果 Web太忙并且由于流量过大而无法处理您的请求时就会导致此问题。请稍后再次连接。
    如果问题依然存在,请与 Web 服务器的管理员联系。
    403.10 禁止访问:配置无效
    此时 Web 服务器的配置存在问题。
    如果问题依然存在,请与 Web服务器的管理员联系。
    403.11 禁止访问:密码已更改
    在身份验证的过程中如果用户输入错误的密码,就会导致此错误。请刷新网页并重试。
    如果问题依然存在,请与 Web服务器的管理员联系。
    403.12 禁止访问:映射程序拒绝访问
    拒绝用户证书试图访问此 Web 站点。
    请与站点管理员联系以建立用户证书权限。如果必要,也可以更改用户证书并重试。

    HTTP 错误 404
    404 找不到
    Web 服务器找不到您所请求的文件或脚本。请检查URL 以确保路径正确。
    如果问题依然存在,请与服务器的管理员联系。

    HTTP 错误 405
    405 不允许此方法
    对于请求所标识的资源,不允许使用请求行中所指定的方法。请确保为所请求的资源设置了正确的 MIME 类型。
    如果问题依然存在,请与服务器的管理员联系。

    HTTP 错误 406
    406 不可接受
    根据此请求中所发送的“接受”标题,此请求所标识的资源只能生成内容特征为“不可接受”的响应实体。
    如果问题依然存在,请与服务器的管理员联系。

    HTTP 错误 407
    407 需要代理身份验证
    在可为此请求提供服务之前,您必须验证此代理服务器。请登录到代理服务器,然后重试。
    如果问题依然存在,请与 Web 服务器的管理员联系。

    HTTP 错误 412
    412 前提条件失败
    在服务器上测试前提条件时,部分请求标题字段中所给定的前提条件估计为FALSE。客户机将前提条件放置在当前资源 metainformation(标题字段数据)中,以防止所请求的方法被误用到其他资源。
    如果问题依然存在,请与 Web 服务器的管理员联系。

    HTTP 错误 414
    414 Request-URI 太长
    Request-URL太长,服务器拒绝服务此请求。仅在下列条件下才有可能发生此条件:
    客户机错误地将 POST 请求转换为具有较长的查询信息的 GET 请求。
    客户机遇到了重定向问题(例如,指向自身的后缀的重定向前缀)。
    服务器正遭受试图利用某些服务器(将固定长度的缓冲区用于读取或执行 Request-URI)中的安全性漏洞的客户干扰。
    如果问题依然存在,请与 Web 服务器的管理员联系。

    HTTP 错误 500
    500 服务器的内部错误
    Web 服务器不能执行此请求。请稍后重试此请求。
    如果问题依然存在,请与 Web服务器的管理员联系。

    HTTP 错误 501
    501 未实现
    Web 服务器不支持实现此请求所需的功能。请检查URL 中的错误,如果问题依然存在,请与 Web服务器的管理员联系。

    HTTP 错误 502
    502 网关出错
    当用作网关或代理时,服务器将从试图实现此请求时所访问的upstream 服务器中接收无效的响应。
    如果问题依然存在,请与 Web服务器的管理员联系。

    HTTP 504 错误

    网关超时 (Gateway timeout)

    这个错误的原因是使用代理服务器或者代理IP引起的,或者由于服务器繁忙造成的,未能从上游服务器获取到请求的响应。

    HTTP 301

      HTTP/1.1 301 Moved Permanently

    HTTP 302

    HTTP 303

    303 See Other 在response头中会加入Location通知浏览器跳到此地址。POST请求的常见响应。

    参考:

    http://zh.wikipedia.org/wiki/HTTP%E7%8A%B6%E6%80%81%E7%A0%81

  • shell下12个for循环例子

    12个例子写的很全,转自

    12 Bash For Loop Examples for Your Linux Shell Scripting

    基本格式1,用for in:

    for varname in list
    do
     command1
     command2
     ..
    done

    基本格式2,c语言形式:

    for (( expr1; expr2; expr3 ))
    do
    command1
    command2 ..
    done

    1. Static values for the list after “in” keyword直接在”in”后面接值

    In the following example, the list of values (Mon, Tue, Wed, Thu and Fri) are directly given after the keyword “in” in the bash for loop.在下面的例子中,变量为day,在Mon,Tue,Wed,Thu和Fri中取值。

    $ cat for1.sh
    i=1
    for day in Mon Tue Wed Thu Fri
    do
     echo "Weekday $((i++)) : $day"
    done
    
    $ ./for1.sh
    Weekday 1 : Mon
    Weekday 2 : Tue
    Weekday 3 : Wed
    Weekday 4 : Thu
    Weekday 5 : Fri

    Caution: The list of values should not be separated by comma (Mon, Tue, Wed, Thu, Fri). The comma will be treated as part of the value. i.e Instead of “Mon”, it will use “Mon,” as value as shown in the example below.注意点:五个不同的值不能用逗号分隔,例如Mon,因为会自动把逗号算入到Mon之内。测试如下:

    $ cat for1-wrong1.sh
    i=1
    for day in Mon, Tue, Wed, Thu, Fri
    do
     echo "Weekday $((i++)) : $day"
    done
    
    $ ./for1-wrong1.sh
    Weekday 1 : Mon,
    Weekday 2 : Tue,
    Weekday 3 : Wed,
    Weekday 4 : Thu,
    Weekday 5 : Fri

    Caution: The list of values should not be enclosed in a double quote. (“Mon Tue Wed Thu Fri”). If you enclose in double quote, it will be treated as a single value (instead of 5 different values), as shown in the example below.注意:五个值不可以用双引号括起来,这会被认为只有一个值

    $ cat for1-wrong2.sh
    i=1
    for day in "Mon Tue Wed Thu Fri"
    do
     echo "Weekday $((i++)) : $day"
    done
    
    $ ./for1-wrong2.sh
    Weekday 1 : Mon Tue Wed Thu Fri

    2. Variable for the list after “in” keyword在”in”后面接变量

    Instead of providing the values directly in the for loop, you can store the values in a variable, and use the variable in the for loop after the “in” keyword, as shown in the following example.在使用前把值赋给变量,在”in”后面接变量。

    $ cat for2.sh
    i=1
    weekdays="Mon Tue Wed Thu Fri"
    for day in $weekdays
    do
     echo "Weekday $((i++)) : $day"
    done
    
    $ ./for2.sh
    Weekday 1 : Mon
    Weekday 2 : Tue
    Weekday 3 : Wed
    Weekday 4 : Thu
    Weekday 5 : Fri

    Caution: As a best practice, you should always quote the bash variables when you are referring it. There are few exceptions to this best practice rule. This is one of them. If you double quote the variable in this for loop, the list of values will be treated as single value. Lot of people fall into this trap. Be careful and do not double quote your variable in the for loop.注意:作为一个良好的习惯,请每次都将值用变量来代替。这里的变量不能用双引号括起来,它会将其视为一个值。测试如下:

    $ cat for2-wrong.sh
    i=1
    weekdays="Mon Tue Wed Thu Fri"
    for day in "$weekdays"
    do
     echo "Weekday $((i++)) : $day"
    done
    
    $ ./for2-wrong.sh
    Weekday 1 : Mon Tue Wed Thu Fri

    3. Don’t specify the list; get it from the positional parameters不指定列表

    If you don’t specify the keyword “in” followed by any list of values in the bash for loop, it will use the positional parameters (i.e the arguments that are passed to the shell script).如果in中不加变量,则在执行时加上即可,例如:

    $ cat for3.sh
    i=1
    for day
    do
     echo "Weekday $((i++)) : $day"
    done
    
    $ ./for3.sh Mon Tue Wed Thu Fri
    Weekday 1 : Mon
    Weekday 2 : Tue
    Weekday 3 : Wed
    Weekday 4 : Thu
    Weekday 5 : Fri

    Caution: Please be careful if you use this method. You should not include the keyword “in” in the for loop. If you leave the keyword “in” without any values, it will not use the positional parameter as shown below. It will not go inside the loop. i.e for loop will never get executed as shown in the example below.使用这种方法一定要小心,保证 in 这个字符都不出现,下面的例子就是没有输出任何信息。

    $ cat for3-wrong.sh
    i=1
    for day in
    do
     echo "Weekday $((i++)) : $day"
    done
    
    $ ./for3-wrong.sh Mon Tue Wed Thu Fri

    Note: Refer to our earlier article to understand more about bash positional parameters.可以查看bash位置参数。

    4. Unix command output as list values after “in” keyword以命令的输出做为列表

    You can use the output of any UNIX / Linux command as list of values to the for loop by enclosing the command in back-ticks ` ` as shown below.使用反引号将要执行的命令引起来,可使结果作为列表。

    $ cat for4.sh
    i=1
    for username in `awk -F: '{print $1}' /etc/passwd`
    do
     echo "Username $((i++)) : $username"
    done
    
    $ ./for4.sh
    Username 1 : ramesh
    Username 2 : john
    Username 3 : preeti
    Username 4 : jason
    ..

    5. Loop through files and directories in a for loop使用当前目录或文件做列表

    To loop through files and directories under a specific directory, just cd to that directory, and give * in the for loop as shown below.定位到指定目录下,用*代替列表。

    The following example will loop through all the files and directories under your home directory.下面的例子使用了/home目录。

    $ cat for5.sh
    i=1
    cd ~
    for item in *
    do
     echo "Item $((i++)) : $item"
    done
    
    $ ./for5.sh
    Item 1 : positional-parameters.sh
    Item 2 : backup.sh
    Item 3 : emp-report.awk
    Item 4 : item-list.sed
    Item 5 : employee.db
    Item 8 : storage
    Item 9 : downloads

    Usage of * in the bash for loop is similar to the file globbing that we use in the linux command line when we use ls command (and other commands).上面的例子显示类似于ls的执行结果。

    For example, the following will display all the files and directories under your home directory. This is the concept that is used in the above for5.sh example.

    cd ~
    ls *

    The following will display all the *.conf file that begins with either a, b, or, c or d under /etc directory.下面显示以a,b,c或d开头,以.conf结尾的文件

    $ ls -1 /etc/[abcd]*.conf
    /etc/asound.conf
    /etc/autofs_ldap_auth.conf
    /etc/cas.conf
    /etc/cgconfig.conf
    /etc/cgrules.conf
    /etc/dracut.conf

    The same argument that is used in the ls command above, can be used in a bash for loop, as shown in the example below.上面的可直接作为列表

    $ cat for5-1.sh
    i=1
    for file in /etc/[abcd]*.conf
    do
     echo "File $((i++)) : $file"
    done
    
    $ ./for5-1.sh
    File 1 : /etc/asound.conf
    File 2 : /etc/autofs_ldap_auth.conf
    File 3 : /etc/cas.conf
    File 4 : /etc/cgconfig.conf
    File 5 : /etc/cgrules.conf
    File 6 : /etc/dracut.conf

    6. Break out of the for loop(for循环中的break)

    You can break out of a for loop using ‘break’ command as shown below.可以使用如下的方式,中断for循环。

    $ cat for6.sh
    i=1
    for day in Mon Tue Wed Thu Fri
    do
     echo "Weekday $((i++)) : $day"
     if [ $i -eq 3 ]; then
       break;
     fi
    done
    
    $ ./for6.sh
    Weekday 1 : Mon
    Weekday 2 : Tue

    7. Continue from the top of the for loop(for循环中的continue)

    Under certain conditions, you can ignore the rest of the commands in the for loop, and continue the loop from the top again (for the next value in the list), using the continue command as shown below.在有些情况下,可以忽略某些之后再回到循环中,使用continue即可做到。

    The following example adds “(WEEKEND)” to Sat and Sun, and “(weekday)” to rest of the days.当循环遇到i=7 或i=8时,显示WEEKEND,然后继续。

    $ cat for7.sh
    i=1
    for day in Mon Tue Wed Thu Fri Sat Sun
    do
     echo -n "Day $((i++)) : $day"
     if [ $i -eq 7 -o $i -eq 8 ]; then
       echo " (WEEKEND)"
       continue;
     fi
     echo " (weekday)"
    done
    
    $ ./for7.sh
    Day 1 : Mon (weekday)
    Day 2 : Tue (weekday)
    Day 3 : Wed (weekday)
    Day 4 : Thu (weekday)
    Day 5 : Fri (weekday)
    Day 6 : Sat (WEEKEND)
    Day 7 : Sun (WEEKEND)

    8. Bash for loop using C program syntax使用C语言for循环语法

    This example uses the 2nd method of bash for loop, which is similar to the C for loop syntax. The following example generates 5 random number using the bash C-style for loop.在文章开头有使用c语言的for循环,下面的例子生成出1-5个数字

    $ cat for8.sh
    for (( i=1; i <= 5; i++ ))
    do
     echo "Random number $i: $RANDOM"
    done
    
    $ ./for8.sh
    Random number 1: 23320
    Random number 2: 5070
    Random number 3: 15202
    Random number 4: 23861
    Random number 5: 23435

    9. Infinite Bash for loop无限循环

    When you don’t provide the start, condition, and increment in the bash C-style for loop, it will become infinite loop. You need to press Ctrl-C to stop the loop.当不设定起始,条件和步长的时候,会变为无限循环,只能通过Ctrl-C来停止。

    $ cat for9.sh
    i=1;
    for (( ; ; ))
    do
       sleep $i
       echo "Number: $((i++))"
    done

    Like we said above, press Ctrl-C to break out of this bash infinite for loop example.

    $ ./for9.sh
    Number: 1
    Number: 2
    Number: 3

    10. Using comma in the bash C-style for loop在c语言类似的循环中使用逗号

    In the bash c-style loop, apart from increment the value that is used in the condition, you can also increment some other value as shown below.在c语言类似的循环中,可以将增长和变量分开。

    In the initialize section, and the increment section of the bash C-style for loop, you can have multiple value by separating with comma as shown below.

    The following for loop is executed a total of 5 times, using the variable i. However the variable j start with 5, and getting increment by 5 every time the loop gets executed.下面的例子将执行5次,但是目标是改变j的值,每一次加5

    $ cat for10.sh
    for ((i=1, j=10; i <= 5 ; i++, j=j+5))
    do
     echo "Number $i: $j"
    done
    
    $ ./for10.sh
    Number 1: 10
    Number 2: 15
    Number 3: 20
    Number 4: 25
    Number 5: 30

    11. Range of numbers after “in” keyword在in列表中使用数字区间

    You can loop through using range of numbers in the for loop “in” using brace expansion.

    The following example loops through 10 times using the values 1 through 10.下面的例子取值1到10,用大括号括起来。

    $ cat for11.sh
    for num in {1..10}
    do
     echo "Number: $num"
    done
    
    $ ./for11.sh
    Number: 1
    Number: 2
    Number: 3
    Number: 4
    Number: 5
    ...

    12. Range of numbers with increments after “in” keyword在in列表中使用数字区间,并以2做为步长。

    The following example loops through 5 times using the values 1 through 10, with an increment of 2. i.e It starts with 1, and keeps incrementing by 2, until it reaches 10.

    $ cat for12.sh
    for num in {1..10..2}
    do
     echo "Number: $num"
    done
    
    $ ./for12.sh
    Number: 1
    Number: 3
    Number: 5
    Number: 7
    Number: 9

    12个for循环的例子很基础很规范,多看优质代码才能更快成长。

  • pptpsetup命令行连接pptp vpn | 拨号

    一般会自带pptpsetup这个工具

    没有的话

    apt-get install pptp-linux

    添加一个vpn连接,执行

    pptpsetup -create vpnname -server xxx.xxx.xxx.xxx -username username -password passwd -encrypt (记得改一下)

    PS:更多选项运行”pptpsetup –help”

    这样其实是写入了/etc/ppp/peers/ 这个目录下面(网上有在这个目录新建文件的方法,看来不如这个方便)

    /etc/ppp/chap-secrets 用户名密码写入到了这个文件

    上线:

    pon vpnname

    下线:

    poff vpnname (全部下线poff -a)

    然后ifconfig查看一下多了ppp0这个网络

    现在还不能通过vpn来走

    因为并不知道数据该怎么走,很明显要配一下路由

    #route 查看现在的默认路由,下面两条操作将默认路由改为vpn的地址,删除原来的默认路由

    route add default gw 10.19.1.1
    route delete default gw xxx.xxx.xxx.yyy

    或者这样更简便

    route del default
    route add default dev ppp0

    这样就能通过vpn来做事了。

     

  • shell操作mysql一则 | sql update 语句

    背景,打算把radius里有几个用户在凌晨没有人上的时候设为disable,需要用到update语句和at命令

    首先在mysql里创建了一个新的帐号,用户名rrr 密码ttt

    要操作的数据库为 radius ,操作函数mysql_opt ,操作表radusergroup

    #!/bin/bash
    #for use:disable the radius users
    #author: jpuyy.com
    #version:
    #history:
    #relate on: at mysql|update
    sql_user=rrr 
    sql_pass=ttt
    sql_opt="-u$sql_user -p$sql_pass -s"
    
    mysql_opt() {
    db_name=$1
    sql_lan=$2
    mysql $sql_opt << EOF
    USE $db_name;
    $sql_lan;
    QUIT
    EOF
    }
    
    data=`mysql_opt radius "UPDATE  radusergroup SET groupname='daloRADIUS-Disabled-Users'  WHERE username in ('aaa','bbb','ccc')"`
    echo $data
  • Debian操作系统编译内核

    转自:

    想用上最新的内核,就需要我们自己去编译新内核了

    安装需求软件包

    apt-get install kernel-package libncurses5-dev fakeroot wget build-essential

    下载新内核

    你可以在这里查看可用的内核 目前最新的为2.6.x

    linux kernel 官方网站:http://www.kernel.org

    cd /usr/src
    wget http://www.eu.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.tar.gz

    解压 创建软链接,切换到软链接中操作

    tar zxvf linux-2.6.26.tar.gz
    ln -s linux-2.6.26 linux
    cd /usr/src/linux

    生成内核文件,首先要复制旧内核的配置文件

    make clean && make mrproper
    cp /boot/config-`uname -r` ./.config
    make menuconfig

    使用下面的步骤来载入旧的内核配置
    1. Load an Alternate Configuration File
    2. Type .config if not already in the textbox
    3. Ok
    4. Do any changes to the kernel modules
    5. Click Exit
    6. Click Yes when asked if you want to save

    编译内核

    make-kpkg clean
    fakeroot make-kpkg –initrd –append-to-version=-custom kernel_image kernel_headers

    这个过程需要很长时间

    安装新内核

    ls -l /usr/src

    到这里,还没有安装内核,
    dpkg -i linux-headers-2.6.26-custom_2.6.26-custom-10.00.Custom_i386.deb
    dpkg -i linux-image-2.6.26-custom_2.6.26-custom-10.00.Custom_i386.deb

    最后重新启动服务器即可

    reboot