-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
254 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# 历史版本 | ||
|
||
## 1.5.0 | ||
|
||
2019-06-21 | ||
|
||
- 增加 kindle 推送功能 | ||
- 增加获取网络请求的耗时和状态码功能 | ||
- 增加查看当前用户大文件的功能 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ | |
Wshell 是集成化的 Linux 服务器脚本,主旨是尽量将常用软件的复杂安装过程和操作一键化,提高工作效率。 | ||
|
||
**适配** | ||
|
||
- MacOS | ||
- Ubuntu | ||
- Debian | ||
- CentOS | ||
|
||
|
||
## 安装 | ||
|
||
### MacOS | ||
|
@@ -43,37 +43,53 @@ $ curl -L https://raw.githubusercontent.com/wxnacy/wshell/master/wshell-installe | |
|
||
**配置环境** | ||
|
||
|
||
```bash | ||
$ echo 'export WS_HOME=${HOME}/.wshell' >> ~/.bashrc | ||
$ echo 'export PATH=${WS_HOME}/bin:$PATH' >> ~/.bashrc | ||
$ echo '. ${WS_HOME}/conf/system/bashrc' >> ~/.bashrc | ||
$ echo '. ${WS_HOME}/conf/bash/bashrc' >> ~/.bashrc | ||
$ source ~/.bashrc | ||
``` | ||
|
||
**查看版本** | ||
|
||
|
||
**更新到最新版本** | ||
|
||
```bash | ||
$ ws update | ||
``` | ||
|
||
## 语法 | ||
|
||
```bash | ||
$ ws[hell] <command> [args...] | ||
``` | ||
|
||
## 命令 | ||
|
||
### 查看版本 | ||
|
||
```bash | ||
$ ws version | ||
``` | ||
|
||
**更新** | ||
### 更新版本 | ||
|
||
更新 Wshell 到最新版 | ||
|
||
```bash | ||
$ ws update | ||
``` | ||
|
||
|
||
## 语法 | ||
### 检查支持软件的安装情况 | ||
|
||
```bash | ||
$ ws[hell] <command> [args...] | ||
$ ws check | ||
``` | ||
|
||
## 参数 | ||
### install | ||
### 安装系统软件 | ||
|
||
一键下载软件,如 | ||
一键安装软件,如 | ||
|
||
```bash | ||
$ wshell install java | ||
|
@@ -109,27 +125,19 @@ zlib1g.dev, libgdbm-dev, libssl-dev, libsqlite3-dev, libbz2-dev, libreadline-dev | |
c++, pcre, pcre-devel, openssl, openssl-devel, epel-release, zlib, zlib-devel, readline, readline-devel, readline-static, openssl-static, sqlite-devel, bzip2-devel, bzip2-libs | ||
``` | ||
|
||
### update | ||
|
||
更新 Wshell 到最新版 | ||
|
||
### check | ||
|
||
查看 Wshell 支持软件的安装情况 | ||
|
||
### os | ||
|
||
查看系统版本信息 | ||
### 查看系统信息 | ||
|
||
```bash | ||
$ ws os | ||
Darwin 10.14.3 brew | ||
# 平台名称 版本号 使用包管理工具 | ||
``` | ||
|
||
### hash | ||
### 计算签名 | ||
|
||
计算 hash 值,可以传入字符串或者文件名 | ||
计算签名,可以传入字符串或者文件名 | ||
|
||
```bash | ||
$ ws <md5|sha1|sha256|sha512> <text|filename> | ||
|
@@ -145,3 +153,58 @@ cf4b95753d3382d3560b1ad4f068db01 | |
$ cat README.md | ws md5 # 接收管道信息 | ||
cf4b95753d3382d3560b1ad4f068db01 | ||
``` | ||
|
||
### 查看大文件 | ||
|
||
```bash | ||
$ ws bf # 查看当前用户下大小超过 100M 的文件 | ||
$ ws bf 1000 # 查看当前用户下大小超过 1000M 的文件 | ||
``` | ||
|
||
### 网络请求 | ||
|
||
```bash | ||
$ ws http code https://wxnacy.com # 查看网络请求的返回状态码 | ||
200 | ||
|
||
$ ws http time https://wxnacy.com # 查看网络请求的耗时情况 | ||
|
||
time_namelookup: 0.520085 # DNS 域名解析的时候,就是把网站转换成 ip 地址的过程 | ||
time_connect: 0.527951 # TCP 连接建立的时间,就是三次握手的时间 | ||
time_appconnect: 0.559406 # SSL/SSH 等上层协议建立连接的时间,比如 connect/handshake 的时间 | ||
time_redirect: 0.000000 # 网址重镜像的时间 | ||
time_pretransfer: 0.559430 # 从请求开始到响应开始传输的时间 | ||
time_starttransfer: 0.571773 # 从请求开始到第一个字节将要传输的时间 | ||
----------------------------- | ||
time_total: 0.571860 # 总时间 | ||
|
||
0.005082 0.011133 0.028282 0.007518 0.000074 | ||
|-- DNS --|-- TCP --|-- SSL --|-- SVR --|-- DTS --| | ||
|------------------ TOTAL 0.052110 ---------------| | ||
``` | ||
|
||
### 时间 | ||
|
||
```bash | ||
$ ws date # 获取当前日期 | ||
2019-06-20 | ||
|
||
$ ws time # 获取当前时间 | ||
21:16:19 | ||
|
||
$ ws datetime # 获取当前日期和时间 | ||
2019-06-20 21:17:56 | ||
``` | ||
|
||
### Kindle | ||
|
||
如果你本地配置了 mutt 邮件发送,然后安装如下方式配置好你的 Kindle 邮箱即可推送 | ||
|
||
```bash | ||
# 配置邮箱 | ||
$ echo "[email protected]" > ~/.config/wshell/kindle | ||
``` | ||
|
||
```bash | ||
$ ws kindle push <bookfile> # 推送 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.4.8 | ||
1.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
wshell bf.py $@ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python | ||
# -*- coding:utf-8 -*- | ||
# Author: wxnacy([email protected]) | ||
# Description: 查找大于某个值的文件,该值默认 100M | ||
|
||
import os | ||
|
||
def format_size(size: int): | ||
'''格式化大小''' | ||
unit = { | ||
0: 'B', | ||
1: 'K', | ||
2: 'M', | ||
3: 'G', | ||
4: 'T', | ||
} | ||
|
||
for i in range(6): | ||
if 1024 ** i <= size < 1024 ** ( i + 1 ): | ||
if i > 0: | ||
size = size / 1024 ** i | ||
return '{:0.1f}{}'.format( size, unit[i]) | ||
return '{}B'.format(size) | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
import timeit | ||
b = timeit.default_timer() | ||
args = sys.argv[1:] | ||
comp_size = 100 # 默认 100 M | ||
if len(args) >= 1: | ||
comp_size = int(args[0]) | ||
|
||
COMP_SIZE = comp_size * 1024 * 1024 # 查找大于该值的文件 | ||
home = os.getenv("HOME") | ||
filelists = [] | ||
join = os.path.join | ||
exists = os.path.exists | ||
getsize = os.path.getsize | ||
for root, dirs, files in os.walk(home): | ||
for f in files: | ||
filepath = join(root, f) | ||
if exists(filepath): | ||
size = getsize(filepath) | ||
if size >= COMP_SIZE: | ||
filelists.append(dict(size = size, filepath = filepath)) | ||
line = '{}\t{}'.format(format_size(size), filepath) | ||
print(line) | ||
|
||
filelists.sort(key=lambda x: x['size'], reverse=True) | ||
print('\n排序后,最大的 10 个文件') | ||
|
||
for f in filelists[:10]: | ||
line = '{}\t{}'.format(format_size(f['size']), f['filepath']) | ||
print(line) | ||
print('\ntime used', timeit.default_timer() - b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
curl -sIL -w "@${WS_HOME}/bin/http/time_format" -o /dev/null $1 | ||
echo '' | ||
ws http time.py $1 | ||
# time=$(curl -sIL -w "%{time_namelookup} %{time_connect} %{time_appconnect} \ | ||
# %{time_redirect} %{time_pretransfer} %{time_starttransfer} %{time_total}" -o /dev/null $1) | ||
|
||
# echo $time | ||
# all=($time) | ||
# echo ${all[@]} | ||
# dns=${all[0]} | ||
# conn=${all[1]} | ||
# echo $dns | ||
# echo $((conn - dns)) | ||
|
||
# out=""" | ||
# DNS: ${dns} | ||
# TCP: $((conn - dns)) | ||
# """ | ||
# echo $out | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env python | ||
# -*- coding:utf-8 -*- | ||
# Author: wxnacy([email protected]) | ||
# Description: | ||
|
||
import subprocess | ||
import shlex | ||
from decimal import Decimal | ||
|
||
def get_request_time(url): | ||
cmd = ''' | ||
curl -sIL -w "{} {} {} {} {} {} {}" -o /dev/null {} | ||
'''.format('%{time_namelookup}', '%{time_connect}', '%{time_appconnect}', | ||
'%{time_redirect}', '%{time_pretransfer}', '%{time_starttransfer}', | ||
'%{time_total}', url) | ||
cmds = shlex.split(cmd) | ||
p = subprocess.Popen(cmds, stdout=subprocess.PIPE) | ||
p.wait() | ||
byte_data = p.stdout.read() | ||
p.stdout.close() | ||
time = byte_data.decode('utf-8') | ||
return time.split(" ") | ||
|
||
if __name__ == "__main__": | ||
import sys | ||
args = sys.argv[1:] | ||
if len(args) < 1: | ||
raise Error('url not null') | ||
url = args[0] | ||
times = get_request_time(url) | ||
dns = Decimal(times[0]) | ||
conn = Decimal(times[1]) | ||
tcp = conn - dns | ||
app_conn = Decimal(times[2]) | ||
ssl = app_conn - conn if app_conn > 0 else 0 | ||
pretransfer = Decimal(times[4]) | ||
starttransfter = Decimal(times[5]) | ||
total = Decimal(times[6]) | ||
server = starttransfter - pretransfer | ||
data_trans = total - starttransfter | ||
l1 = ' {:0.6f} {:0.6f} {:0.6f} {:0.6f} {:0.6f}'.format( | ||
dns, tcp, ssl, server, data_trans) | ||
l3 = '|-- DNS --|-- TCP --|-- SSL --|-- SVR --|-- DTS --|' | ||
l4 = '|------------------ TOTAL {:0.6f} ---------------|'.format(total) | ||
print(l1) | ||
print(l3) | ||
print(l4) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env bash | ||
# Author: wxnacy([email protected]) | ||
# Description: 推送书籍到 kindle | ||
# vim ${HOME}/.config/wshell/kindle | ||
# [email protected] | ||
|
||
. ${HOME}/.config/wshell/kindle | ||
|
||
path=$1 | ||
|
||
if [ ! -f $path ] | ||
then | ||
echo "Can not find the file '$path'" | ||
exit 0 | ||
fi | ||
|
||
mutt $email -a $path < /dev/null | ||
echo 'Success!' | ||
|