echo

显示指定行的内容

大憨熊 提交于 2020-01-12 19:11:20
显示指定行的内容 出处:http://www.cn-dos.net/forum/viewthread.php?tid=21647 This page shows how to read specific lines from a text file. There are many ways to have the for /f command read the input file, for instance:- for /f "delims=" %%a in (input.txt) do ... for /f "delims=" %%a in ('type input.txt') do ... for /f "delims=" %%a in ('more ^< input.txt') do ... However, only the last method (using the more command) will give consistent results across Windows NT, 2000, XP and 2003. The first method does not recognise unicode files. Also, the usebackq switch must be used if the input filename contains

异常处理

前提是你 提交于 2020-01-12 15:28:13
<?php //异常处理 //固定格式 try{ echo 1; throw new Exception("Error Processing Request", 1); echo 2; }catch(Exception $e){ echo $e; echo "<br>"; echo $e -> getMessage(); echo "<br>"; echo $e -> getCode(); } /* * 注意:try catch之间不能加任何代码 * 注意:try-catch是一种结构,一个try至少对应一个catch */ ?> 自定义异常处理类 <?php class myException extends Exception { function demo(){ echo "执行第二套方案<br>"; } } try{ echo "love<br>"; throw new myException("黑恶黑呵呵呵"); echo "you<br>"; }catch(myException $e){ echo $e; echo "<br>"; echo $e->getMessage(); echo "<br>"; echo $e->getCode(); echo "<br>"; $e -> demo(); }catch(Exception $e){ echo $e; echo "

php上传文件和下载文件

泪湿孤枕 提交于 2020-01-12 11:52:53
单文件上传 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> <!-- 判断变量$_files是否为空 --> <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES

shell编程之函数定义及使用

不羁岁月 提交于 2020-01-12 07:40:59
一.函数定义 #!/bin/sh #func1.sh hello() ##函数定义 {   echo "Hello there today's date is 'date +%Y-%m-%d' "   #return 2 ###返回值其实是状态码,只能在[0-255]范围内 } echo "now going to the function hello" hello #echo $? 获取函数的return值 echo "back from the function" 函数调用:function hello() 或 function hello 或 hello 注意:1.必须在调用函数地方之前,先声明函数,shell脚本是逐行运行,不会像其它语言一样先预 编译    2.函数返回值,只能通过$?系统变量获得,可以显示加:return返回,如果不加,将以最后 一条命令运行结果,作为返回值。return后跟数值n(0-255) 脚本高度:sh-vx helloWorld.sh或者在脚本中增加set -x 二.函数参数 #!/bin/bash #fun1.sh funWithParam(){   echo "第一个参数为 $1!"   echo "第二个参数为 $2!"   echo "第十个参数为 $10!"   echo "第十个参数为 ${10}!"   echo "第十一个参数为

windows下自动删除n天前的文件

*爱你&永不变心* 提交于 2020-01-12 07:38:27
使用windows2003下的内置命令forfiles配合计划任务可以实现自动删除n天前的文件。 windows2003中设定自动执行的计划任务很简单。 一、脚本编写 forfiles命令用法: Forfiles 从文件夹或树中选择要进行批处理的文件。 语法 forfiles [ /p Path ] [ /m SearchMask ] [ /s ] [ /c Command ] [ /d [{ + | - }] [{ MM / DD / YYYY | DD }]] 参数 /p Path 指定 Path ,表明要从哪里开始搜索。默认的文件夹是当前工作目录,该目录通过键入句号 (.) 指定。 注:绝对路径应该包含在双引号中,且路径应该由反斜杠分割:example:"D:\HOME\Desktop\62backup" /m SearchMask 按照 SearchMask 搜索文件。默认的 SearchMask 是 *.* 。 /s 指示 forfiles 在子目录中搜索。 /c Command 在每个文件上运行指定的 Command 。带有空格的命令字符串必须用引号括起来。默认的 Command 是 "cmd /c echo @file" 。 /d [{ + | - }] [{ MM / DD / YYYY | DD }] 选择日期大于或等于 ( + )(或者小于或等于 ( - )

Nginx日志分析脚本

百般思念 提交于 2020-01-12 01:06:11
运维工作是一个比较复杂的工作,有时候面对上万条的日志,如何作分析?难道一条条的分析? 聪明的人会选择脚本,这就是为什么现在提倡自动化运维的原因吧,废话不多说,直接上脚本。 vim /data/scripts/log_analysis.sh #!/bin/bash ############################################### # Desc :nginx日志分析脚本 # # Author : Bertram # # Date : 2019-12-21 # # Copyright : Personal belongs # ############################################### public(){ echo "" read -p "请输入要分析的访问日志: " log_file echo "" if [ ! -f $log_file ];then echo "未找到: ${log_file}" exit 1 fi if [ ! -s $log_file ];then echo "${log_file}是空文件" exit 1 fi #输出日志访问量排名前top_num条数据,可自定义 top_num=5 input_file=`echo $log_file | awk -F '/' '{print $(NF)}'`

用户集中管理

放肆的年华 提交于 2020-01-12 00:23:25
使用/etc/sudoers里设置用户别名、命令别名来设置各个用户类型所需要的权限和命令来控制用户权限和所能使用的命令 主机别名 # Host_Alias FILESERVERS = fs1, fs2 用户别名 组别名 # User_Alias ADMINS = jsmith, mikem # User_alias AdminsGroup=%xbin 命令别名 # Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum 配置 用户 主机=(主机) 命令 root ALL=(ALL) ALL sudoers文件配置 [root@xbin-S ~]# grep -v "##" /etc/sudoers # Host_Alias FILESERVERS = fs1, fs2 # Host_Alias MAILSERVERS = smtp, smtp2 # User_Alias ADMINS = jsmith, mikem # Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin

初入Shell

风格不统一 提交于 2020-01-12 00:07:23
shell 第 1 章 Shell 概述 大数据 程序员 为什么要 学习 Shell 呢?   1 ) 需要看懂运维人员 编写的Shell程序。   2) 偶尔会编写一些简单 Shell 程序 来管理集群、 提高开发效率 。    第 2 章 Shell 解析器   ( 1 ) Linux 提供的 Shell 解析器有: [atguigu@hadoop101 ~]$ cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/dash /bin/tcsh /bin/csh   ( 2 ) bash 和 sh 的关系 [atguigu@hadoop101 bin]$ ll | grep bash -rwxr-xr-x. 1 root root 941880 5月 11 2016 bash lrwxrwxrwx. 1 root root 4 5月 27 2017 sh -> bash   ( 3 ) Centos/Ubutun 默认的 解析 器 是bash [atguigu@hadoop102 bin]$ echo $SHELL /bin/bash 第 3 章 Shell 脚本 入门 1 . 脚本格式 脚本以 #!/bin/bash 开头 (指定解析 器 ) 2 . 第一个 Shell 脚本 :helloworld ( 1 )需求:创建一个

SHELL脚本编程生产案例

拈花ヽ惹草 提交于 2020-01-11 22:38:42
Shell脚本编程 基础 编写脚本 backup.sh,可实现每日将/etc/目录备份/backup/etcYYYY-mm-dd中 #!/bin/bash cp -av /etc/ /data/etc\ ` date +%F ` 编写脚本 hostping.sh,接受一个主机的IPv4地址做为参数,测试是否可连通。如果能ping通,则提示用户“该IP地址可访问”;如果不可ping通,则提示用户“该IP地址不可访问” #!/bin/bash ping -w3 -c3 $1 & > /dev/null && echo "该IP地址可访问" || echo "该IP地址不可访问" 编写脚本 checkdisk.sh,检查磁盘分区空间和inode使用率,如果超过80%,就发广播警告空间将满 #!/bin/bash CHECKDISK = ` ( df ; df -i ) | egrep "^/dev/sda" | tr -s ' ' % | cut -d '%' -f5 | sort -nr | head -1 ` [ $CHECKDISK -gt 80 ] & > /dev/null && echo "磁盘空间或节点编号空间已达到80%" | mail -s "空间已满" root 编写脚本 per.sh,判断当前用户对指定参数文件,是否不可读并且不可写 #!/bin/bash [ !

Nginx 高级配置

早过忘川 提交于 2020-01-11 18:38:55
目录 Nginx 高级配置 Nginx 状态页 Nginx 第三方模块 Nginx 变量使用 内置变量 自定义变量 Nginx 自定义访问日志 自定义默认格式日志 自定义json格式日志 json格式的日志访问统计 Nginx 压缩功能 https 功能 ssl 配置参数 自签名 证书 Nginx证书配置 实现多域名HTTPS 关于favicon.ico 安全选项 隐藏Nginx版本号: 升级OpenSSL版本: Nginx 高级配置 Nginx 状态页 基于nginx模块ngx_http_auth_basic_module实现,在编译安装nginx的时候需要添加编译参数--withhttp_stub_status_module,否则配置完成之后监测会是提示语法错误。 配置示例: [root@ubuntu ~]#vim /apps/nginx/conf/conf.d/pc.conf location /nginx_status { # 这项值是什么访问后面的uri就加什么。 stub_status; allow 192.168.0.0/16; # 只允许这个网段查看 allow 127.0.0.1; # 只允许本机查看 deny all; # 拒绝所有 } # 最后的意思就是允许192.168.0.0/16、127.0.0.1(本机)其他的都拒绝。 # 重新加载服务 [root