gqhp'xGPiyk<'">xDVOFL: 44 items found.

Monitor a website with curl command

Hey there, tech enthusiasts! In this blog post, we'll embark on a journey to create a robust website monitoring system using the Bash shell. We'll dive into the intricacies of checking website availability, handling timeouts, and sending notifications via curl when things go awry.

  1. Laying the Foundation:

    Begin by opening your favorite terminal emulator and creating a new Bash script file. We'll call it "website_monitor.sh." This script will serve as the brain of our monitoring system.

More ~

tcpdump常用命令

监视指定主机的数据包

打印所有进入或离开sundown的数据包.

tcpdump host sundown

也可以指定ip,例如截获所有210.27.48.1 的主机收到的和发出的所有的数据包

tcpdump host 210.27.48.1 

打印helios 与 hot 或者与 ace 之间通信的数据包

tcpdump host helios and ( hot or ace )

截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信

tcpdump host 210.27.48.1 and (210.27.48.2 or 210.27.48.3 ) 

打印ace与任何其他主机之间通信的IP 数据包, 但不包括与helios之间的数据包.

tcpdump ip host ace and not helios

如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包,使用命令:

tcpdump ip host 210.27.48.1 and ! 210.27.48.2

截获主机hostname发送的所有数据

tcpdump -i eth0 src host hostname

监视所有送到主机hostname的数据包

tcpdump -i eth0 dst host hostname
More ~

Delete lines with sed command

Sed Command to Delete Lines: Sed command can be used to delete or remove specific lines which matches a given pattern or in a particular position in a file. Here we will see how to delete lines using sed command with various examples.

More ~

linux命令: awk

awk

文本和数据进行处理的编程语言

补充说明

awk 是一种编程语言,用于在 linux/unix 下对文本和数据进行处理。数据可以来自标准输入(stdin)、一个或多个文件,或其它命令的输出。它支持用户自定义函数和动态正则表达式等先进功能,是 linux/unix 下的一个强大编程工具。它在命令行中使用,但更多是作为脚本来使用。awk 有很多内建的功能,比如数组、函数等,这是它和 C 语言的相同之处,灵活性是 awk 最大的优势。

awk 命令格式和选项

语法形式

awk [options] 'script' var=value file(s)
awk [options] -f scriptfile var=value file(s)
More ~

shell date 格式化

date  --date="STRING"
date  --date="next Friday"
date  --date="2 days ago"
date  --date="yesterday"
date  --date="yesterday" +"%format"
# Get yesterday's date in dd-mm-yy format
date  --date="yesterday" +"%d-%m-%y"
date  --date="yesterday" +"%m-%d-%y" # US date format
date  --date="yesterday" +"%Y-%m-%d" # YYYY-mm-dd format
## store y'day date in a shell variable called yday and display it ##
yday=$(date  --date="yesterday" +"%Y-%m-%d")
echo "$yday"
  • You can use fortnight for 14 day.
  • week for 7 days.
  • hour for 60 minutes
  • minute for 60 seconds
  • second for one second
  • You can also use this / now / today keywords to stress the meaning.
date --date='fortnight'
date --date='5 fortnight'
date --date='fortnight ago'
date --date='5 fortnight ago'
date --date='2 hour'
date --date='2 hour ago'
date --date='20 minute'
date --date='20 minute ago'
date --date='this Friday'
## OR ##
date --date='next Friday'

Set System Date & Time?

date --set='+30 minutes'
date --set='1 day ago'
More ~

ubuntu: Read-only file system

文件系统挂了,变成只读模式。supervisor无法启动,就连ping 域名时无法解析dns,想要修改/etc/resolve.conf,只读也写不进去。
试下往临时目录写也是这:

touch /tmp/aaa.txt
touch: cannot touch '/tmp/aaa.txt': Read-only file system
More ~

为localhost一步生成自签名证书

为localhost一步生成自签名证书

openssl req -x509 -days 365 -out localhost.crt -keyout localhost.key \
  -newkey rsa:2048 -nodes -sha256 \
  -subj '/CN=localhost' -extensions EXT -config <( \
   printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
More ~

flask: serve static file

Send a file from a given directory with :func:send_file. This
is a secure way to quickly expose static files from an upload folder or something similar.

from flask import Flask, request, send_from_directory

# set the project root directory as the static folder, you can set others.
app = Flask(__name__, static_url_path='')

@app.route('/js/<path:path>')
def send_js(path):
    return send_from_directory('js', path)

if __name__ == "__main__":
    app.run()
More ~

SSE (Server-sent events) 技术详解

SSE ( Server-sent Events )是 WebSocket 的一种轻量代替方案,使用 HTTP 协议。

严格地说,HTTP 协议是没有办法做服务器推送的,但是当服务器向客户端声明接下来要发送流信息时,客户端就会保持连接打开,SSE 使用的就是这种原理。

More ~