换行符

换行符\r\n和\n的关系和区别可以追溯到60年前,打字机广泛被使用的时代。 在打字机还刚刚被发明的时候,人们输入完一行字之后,需要两个动作才能开始输入下一行的内容。 滚动滚轮,让纸张往上移动一行, 即是 \n 操作; 移动 打字的指针到 行首, 即是\r 。 上面两个操作没有顺序的要求, 1->2 ; 2->1 都可以。 windows Windows 操作系统 的文本对 new line的 编码 使用的是 2->1 的 组合操作; unix Linux/Unix 操作系统 则只使用操作 1 。 A line feed means moving one line forward. The code is \n. A carriage return means moving the cursor to the beginning of the line. The code is \r. Windows editors often still use the combination of both as \r\n in text files. Unix uses mostly only the \n. ...

November 17, 2021 · datewu

Expect自动化工具简介

公司服务器使用了两层跳板机,外面的一台我们管它叫 server A, 另外一台 叫它 server B。 虽然我不知道这种双保险给公司带来了多少安全感,但是我知道我的运维效率降低了差不多90%吧 :>。 server A被直接暴露在公网上, 我们不能使用 ssh key 只能使用 password认证ssh。 这还不算完,server A每3小时改一次自己的root密码。 后面的server B跳板机器的自我安全感就强多了,server B可以直接免密使用ssh key登陆所有的内网服务器,而且允许server A免密登陆到自己。 我决得这样两次登录很浪费时间,于是写了个脚本从外网一次性登陆到server B服务器上。 expect 脚本 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #!/usr/bin/expect -f # for anyone not familar with expect # should read this awesome post # https://www.pantz.org/software/expect/expect_examples_and_tips.html set timeout 15 ### CHANGE pwd every 3h set pwd "mySuperSecretpwd123" set nested_ssh "ssh server_B" ## for debug # log_user 0 # exp_internal 1 send_user "going to connected to server A\n" spawn ssh -q -o StrictHostKeyChecking=no server_A expect { timeout { send_user "\ntimeout Failed to get password prompt, is VPN on?\n"; exit 1 } eof { send_user "\nSSH failure for server A\n"; exit 1 } "*assword:" } send "$pwd\r" expect { timeout {send_user "\nSSH failure for server B\n"; exit 1 } "Last login:*" } send "$nested_ssh\r" interact 基本语法 简单说下基本流程如下: ...

March 19, 2020 · datewu

bc语言

base 通过修改ibase和obase可以实现各种进制的转化,比如十进制和二进制和十六进制之间的转换; If you aren’t familiar with conversion between decimal, binary, and hexadecimal formats, you can use a calculator utility such as bc or dc to convert between different radix representations. For example, in bc, you can run the command obase=2; 240 to print the number 240 in binary (base 2) form. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #!/bin/bash ❯ bc -q ibase 10 obase 10 1+ 3 *3 10 obase=2 245 11110101 255 11111111 192 11000000 168 10101000 1 1 172 10101100 obase=16 34 22 172 AC ^D% syntax 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 bc An arbitrary precision calculator language. More information: https://manned.org/bc. - Start bc in interactive mode using the standard math library: bc -l - Calculate the result of an expression: bc <<< "(1 + 2) * 2 ^ 2" - Calculate the result of an expression and force the number of decimal places to 10: bc <<< "scale=10; 5 / 3" - Calculate the result of an expression with sine and cosine using mathlib: bc -l <<< "s(1) + c(1)"

October 22, 2018 · datewu