分类 shell脚本学习 articles

xmllint命令处理xml与html

xmllint是一个很方便的处理及验证xml、处理html的工具,linux下只要安装libxml2就可以使用这个命令。首先看下其结合–html 、–xpath参数处理html时的例子: 1curl http://www.123cha.com/ip/?q=8.8.8.8 2>/dev/null | xmllint --html --xpath "//ul[@id='csstb']" - 2>/dev/null | sed -e 's/<[^>]*>//g' 上例中主要是通过在123cha上查询的IP地……

Continue reading

shell字符串操作小结

在写shell脚本时,经常会涉及到字符串相关操作。有很多命令语句,如:awk,sed都可以做字符串各种操作。 其实shell内置一系列操作符号,可以达到类似效果,大家知道,使用内部操作符会省略启动外部程序的等待时间,因此速度会非常的快。 一、判断读取字符串值 表达式 含义 ${var} 变量var的值……

Continue reading

${string::N}和${string:N}字符提取

有文件file,内容为1234567898453613025(n个数字),编写程序实现每隔4个数字就换行。脚本编写如下: ${string::N}提取前N个字符,${string:N}提取N个之后的字符 。 1# cat ./test.sh 2#!/bin/bash 3test=1234567898453613025 4num_test=`echo ${#test}` 5num=$[num_test/4 + 1 ] 6for i in `seq $num` 7do 8 echo -ne "${test::4}" 9 test=`echo ${test:4}` 10 echo 11done 执行后的结果是: 1# ./test.sh 21234 35678……

Continue reading

shell贪婪匹配

有时候对一段文字只提取其中的一部分,可以借助shell的贪婪匹配实现,%是从右向左匹配,#则是从左向右匹配,如下实例: 1[root@www ~]# qq=www.qq.com 2[root@www ~]# echo ${qq#*.} //排除第一个 3qq.com 4[root@www ~]# echo ${qq##*.} //排除前两个 5com 6[root@www ~]# echo ${qq%.*} //排除后一个 7www.qq 8[root@www ~]# echo ${qq%%.*} //排除后两个 9www 10[root@www ~]# 上例中是以点为分割的,不是以“qq”做为分割 。下面结合实……

Continue reading

windows下rsysnc提示password file must be owned by root when running as root的解决办法

这算是个老问题了,每次在windows主机上通过cwrsync向服务端同步数据的时候都会遇到,这次总结记录下吧。错误代码为: 1password file must be owned by root when running as root 在linux上设置rsync的时候,需要将passwordfile设置为600权限。所以在windows上我们也可以用其自带的chmo……

Continue reading

vim 查找时忽略大小写

默认情况下 vim 的查找都是区分大小写的, 这种查找方式有利于准确快速的定位到目标, 但是有时候vim的使用者也不一定能够确认那个单词的大小写情况, 这种情况下就要用到大小写忽略了. 实现这个操作有两种方式. 方式1 指令设定: 1:set ic(ignorecase 的缩写) 忽略大小写 2:set noic(noignorecase 的缩写) 不忽略大小写 输入了上述指令, 当每次的……

Continue reading

linux下删除空行的几种方法

在查看linux下的配置文件时,为了便于一目了然的查看,经常会删除空行和#头的行。而linux在删除空行的方法很多,grep、sed、awk、tr等工具都能实现。现总结如下: 1、grep 1grep -v '^$' file 2、sed 1sed '/^$/d' file 或 sed -n '/./p' file 3、awk 1awk '/./ {print}' file 或 awk '{if($0!=" ") print}' 4、tr 1tr -s "n" 除此之外,vim也……

Continue reading

shell中的getopt与getopts

在shell脚本之shift和getopts篇中有提到getopts,除了bash自带的内部变量getopts外,util-linux-ng包还提供了一个工具getopt ,该工具较bash内置的getopts更强大,其不仅支持短参-s,还支持–longopt的长参数,甚至支持-l……

Continue reading

shell脚本之shift和getopts

在系统服务和一些其他脚本中都可以看到shift和getopts参数的使用,尤其是前者。本篇就针对两者在linux shell 下的使用做下小结。 一、shift参数的使用 很多脚本执行的时候我们并不知道后面参数的个数,但可以使用$*来获取所有参数。但在程序处理的过程中有时需要逐个的将$1、$2、……

Continue reading

proc与awk实时网卡流量监控

通过/proc/net/dev该文件可以获取所有网卡的时时数据信息。通过/sys/class/net/下的文件同样可以获取每块网卡更详细的信息。在cnblogs博客园上看到程默的博客中有一篇使用awk 程序精妙的搞了一个网卡实时流量监控脚本。程序虽然写的非常不错,不过统计的只是网卡……

Continue reading

Latest articles

Categories

Tags

ACL AD AES AI AWS Ansible Atlassian Azure BMC Blockchain Brocade CDH5 CL210 Cobbler Confd C语言 DDOS DISTINCT DNS Duckdb EKS ELK GCP Ghost Git Glusterfs Go Godaddy Grafana HBA HCIE Hotspot HttpWatch IBM IIS IOS InfluxDB Ingress InnoDB JavaScript Jinja2 KVM Keepalived Mplayer MySQLdb Netlify OpenResty PM PostgreSQL QoS RH318 RH442 RHCA RHCE RHEV RSA SRE SecureCRT Statuscode SublimeText2 TC Telecom Tencentcloud VBA aira2 alpine android anpic apache apm apparmor appfog apr apt-get aria2 array atop audit awk awstats axel backdoor backup bamboo bash bat benchmark bigdata bin bind bitwise book bootstrap bsd c1000 cache capistrano catlog centos centos7 chatops chattr check_mk checkinstall cisco clearall clickhouse cloud-desktop cmdb cms collectd comm compress conver corosync cpu crontab crunchbang css curl date decode dell desktop devops df dhcp diff diskpart django docker dos2unix dpkg drupal etcd excel fail2ban fastcgi fdisk fiddler find firewalld flask flvtool ftp function fuser geek gin github gitlab glances golang google gooupadd graphviz gravatra grep grub2 hadoop haproxy hardware heartbeat helm hexdump hhvm history html http/html/web httplogs https huawei huaweicloud hugo icmp iconv ifconfig inotify iopp ipmitool iptables iredmail iscsi isito it-news java jdk jenkins jira join joomla k3s k8s kdump kernel kingate lamp last leetcode lib light-http linux linux高级篇 ln ls lsi lsof lvm lvs mac mail man mark markdown matplotlib maven memcached microservice mimikatz mkdocs mkpasswd mmonit mod_jk mongodb monit monitor mono moodle mosh mount mpm mrtg mtr my.cnf mysql mysqlbinlog mysqld_multi mysqldump mysqlhotcopy nagios nc nethogs nexus nfs nginx nmon nocatlog node.js nrpe ntfs ntop ntp obs ocr open-falcon openbox opencv openldap openssl openstack oracle oswatch paas pacemaker pam pandas parted pcp pcre pdf percona perl pexpect pgrep php php-fpm ping plsql develope postfix powershell prettify proc prometheus puppeteer pushd pwgen pxe pyecharts python python模块 radmin raid rdesktop read redhat redis redmine regex rh134 rhel7 rhel8 rm rman rootkit route rpm rpmforge rrdtool rsync rsyslog safe saltstack samba scapy screen sed selenium selinux seo seq session set shc sheepdog shell shopt sitemap skydns smokeping snffier snmp socket soft sort spider sql sqlserver squid ss ssh sshpass strace strings su sudo suse svn sysbench syslog-ng sysstat systemd t tar tcpcopy tcpdump tech telnet tengine test testlink threads time tmux tomcat touch tr tsar twisted ubuntu udev ulimit unix unixbench user-agent useradd varnish vbs vercel vi vim visudo vmstat vmware vnc voice vpn vscode vsftp vsftpd vue watchdog web webcam webistrano wget wiki windows wol wordpress workshop wsl x-windows xampp xcache xmllint xtrabackup yule yum zabbix zeromq zip zonetime zookeeper 下载工具 云主机 云原生 代理 加密 古意 吐槽 圈里圈外 娱乐 字符串函数 安全 平台架构 意林 推理 提权 故事汇 故障案例 数据结构 每日看点 民国史 生活 科学记录 站长管理工具 算法 管理 网站架构 翻墙 股票 行业 诗韵 负载均衡 远程管理 面试题

Links

Meta