linux的一些运维指令和技巧

本文发布时间: 2019-Mar-22
最近一段时间加强了对liunx的学习和实践。学到了一些不错的技巧和方法。切实感觉到了linux一切皆文本的的魅力。最近一周开启轻测,抽时间记录一下。状态相关查看机器cpu型号: #cat /proc/cpuinfo查看线程占用CPU: #top -H -p pidshell带参数参数在shell中使用1,2代替传入的参数。如下脚本调用的时候如: ./test.sh 800 4#!/bin/sh #test.shcenter_ip=http://115.182.4.26:8080#参数center_ip: 中心服务器的IPserver_id=998if [ $2 ]; then server_id=$2 fi#参数server_id 服务器IDstatus=4if [ $1 ]; then status=$1 fi#参数status 服务器启动状态(1/新服,2/良好, 3/爆满, 4/调试, 5/激活码)curl -d 'server_id=$server_id&command=2&command_cls=1&command_key=0&command_content={status=$status, tick=0}' '$center_ip'makefile带参数同上面shell一样,makefile也可以带参数执行。参数在makefile中使用(arg1),(arg2)代替传入的参数。makefile在执行的时候可以带上参数名如: make start serverId=1000 status=3.PHONY: start stop center_ip = http://115.182.4.26:8080#参数center_ip: 中心服务器的IPserver_id = 998#参数server_id 服务器IDstatus = 2#参数status 服务器启动状态(1/新服,2/良好, 3/爆满, 4/调试, 5/激活码)start: ifneq ($(server_id), 0) curl -d 'server_id=$(server_id)&command=2&command_cls=1&command_key=0&command_content={status=$(status), tick=0}' $(center_ip)endifstop: ifneq ($(server_id), 0) curl -d 'server_id=$(server_id)&command=2&command_cls=1&command_key=0&command_content={status=0, tick=0}' $(center_ip)endif在makefile和shell中使用curl。curl在linux中的makefile和shell中基本可以直接使用,不用安装。curl默认使用get方式。如下curl -u username http://115.182.4.26:8080使用post方式,-d参数表示post方式,格式curl -d context url。如下curl -d 'server_id=800&command=2&command_cls=1&command_key=0' http://115.182.4.26:8080文本日志相关文本写入日志文件,通常可以使用echo可以实现。#覆盖方式写入,使用>操作符echo '测试内容' > test.log #追加方式写入echo '测试内容' >> test.log #写入日期的方式echo $(date '+%Y-%m-%d %H:%M:%S') >> test.log查询日志并输出有时候日志文件会非常大,查看起来会非常费劲,导入到windows下也是打不开。这里的不说,linux在处理文本方面还是比较强大的。虽然看起来不直观。可以利用grep查找后很方便的重定向到文件,只看有用的部分。#grep something > test.log查看日志有时候不方便用cat的时候,可以使用下tail来查看,例如:--查看日志文件的最后200行#tail -200 test.log--动态查看日志文件,日志文件更新后,会显示出来#tail -f test.log暂时只记录这么多,后续有时间在补上来。


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:08pm
栏目列表