shell script练习】的更多相关文章

一.格式 1.1 开头 必须以 "# !/bin/bash"  开头,告诉系统这是一个bash shell脚本.注意#与!中间有空格. 二.语法 2.1 数值运算 可以用declare -i声明为数值类型,也可以用 var = $((数值运算)),注意是两个括号 2.3 善用判断式 2.3.1 test命令 test命令可以测试,可以利用测试的结果走后续流程.测试文件和文件属性还是比较方便的. :~/test$ test -e nofile && echo "…
一.shell script的编写与执行 1.shell script 的编写中还需要用到下面的注意事项: a.命令的执行是从上到下,从左到右地分析与执行 b.命令.参数间的多个空白都会被忽略掉 c.空白行也将被忽略掉, 并且[tab]按键所得的空白同样视为空格键  d.如果读取到一个Enter符号(CR),就尝试开始执行该行(或该串)命令 e.至于如果一行的内容太多,则可以使用"\[Enter]"来扩展至下一行  f."#"可作为批注. 2.执行文件(/home/…
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article introduces a shell script to perform linux system health check.This script collects system information and status like hostname, kernel version, uptim…
执行脚本的几种方式: 1. sh a.sh 或者  bash a.sh  调用的是 /bin/bash 进程执行的,所以脚本不需要执行权限. 2. 直接使用绝对路径执行, /home/script/a.sh  ,脚本需要有执行权限,如果没有权限可执行 chmod a+x a.sh 加入执行权限. (lampp启动数据库用的就是: /opt/lampp/lampp startmysql ) sh03.sh 根据时间创建目录 #!/bin/bash echo -e "I will use 'touc…
这些年我们一起搞过的持续集成~Jenkins+Perl and Shell script ##转载注明出处:http://www.cnblogs.com/wade-xu/p/4378224.html 部门用持续集成已经很久了,但其实使用起来还是很麻烦的,每当要给一个新项目set up持续集成的环境,虽然是Copy一些现有的jobs, 但是许多参数,变量需要去改,然后还有调试,少说3,4天搞一下,非常不方便. 最近比较空,就把现有的持续集成系统升级改造下,job用一套模板,全部参数化,只要修改配置…
CentOS 的tomcat安装目录:/usr/local/tomcat vi MyTomcatUitl.sh          创建文件chmod u+x MyTomcatUtil.sh   赋执行权限 shell script : #!/bin/bash # tomcat启动,停止,日志显示脚本 == ''];then echo "请带一个参数执行命令:start 启动tomcat,stop 停止tomcat , logs 查看tomcat动态日志" exit fi == 'sta…
Shell script for logging cpu and memory usage of a Linux process http://www.unix.com/shell-programming-and-scripting/223177-shell-script-logging-cpu-memory-usage-linux-process.html…
从程序员的角度来看, Shell本身是一种用C语言编写的程序,从用户的角度来看,Shell是用户与Linux操作系统沟通的桥梁.用户既可以输入命令执行,又可以利用 Shell脚本编程,完成更加复杂的操作.在Linux GUI日益完善的今天,在系统管理等领域,Shell编程仍然起着不可忽视的作用.深入地了解和熟练地掌握Shell编程,是每一个Linux用户的必修 功课之一. Linux的Shell种类众多,常见的有:Bourne Shell(/usr/bin/sh或/bin/sh).Bourne…
shell script 的追踪与 debug scripts 在运行之前,最怕的就是出现语法错误的问题了!那么我们如何 debug 呢?有没有办法不需要透过直接运行该 scripts 就可以来判断是否有问题呢?呵呵!当然是有的!我们就直接以 bash 的相关参数来进行判断吧! [root@www ~]# sh [-nvx] scripts.sh 选项与参数: -n :不要运行 script,仅查询语法的问题: -v :再运行 sccript 前,先将 scripts 的内容输出到萤幕上: -x…
简单的 shell script 练习 简单范例 对谈式脚本:变量内容由使用者决定 [root@www scripts]# vi sh02.sh #!/bin/bash # Program: # User inputs his first name and last name. Program shows his full name. # History: # 2005/08/23 VBird First release PATH=/bin:/sbin:/usr/bin:/usr/sbin:/u…
本文介绍下,学习shell script编程的入门知识,通过几个入门实例,带领大家走进shell script的神圣殿堂,呵呵,有需要的朋友参考下. 本文转自:http://www.jbxue.com/article/13302.html linux基础之Shell Script 1 Shell Scipt 使用指令和基本程序设计结构写成的程序,可以完成复杂的处理流程 1.1 程序书写 复制代码代码如下: #!/bin/bash # Program: #       This program s…
A chain no stronger than its weakest link. "一着不慎,满盘皆输" 参考资料:鸟哥的Linux私房菜 基础学习篇(第三版)  Linux Shell脚本攻略     Linux程序设计(第四版) 一.什么是shell script 1.什么是shell script 简单来说,shell script(程序化脚本)是利用shell功能所写的一个“程序”,它拥有自己的语法特性 2.为什么要学shell script 对于一个初学者来说,我觉得就那…
在shell script中,$*和$@都是获取所有的命令行参数,但是这两者在使用的过程中会有细微的差别,差别主要是在有没有使用双引号,即是直接使用$*,$@,还是使用"$*","$@". 直接使用$*,$@ #!/bin/bash count= for param in $*;do echo "\$* Parameter #$count = $param" count=$[ $count + ] done count= for param in…
第一个Shell脚本——HelloWorld [root@localhost ~]# vi sh01.sh #!/bin/bash #!表明使用哪种shell # this is my first shell script #注释部分 echo -e "hello world!" exit 0 [root@localhost~]# sh sh01.sh #使用bash或者sh命令执行sh文件 hello world! 第二个Shell脚本——从终端接收用户输入到变量中 第三个Shell…
PS:在学习python的时间里,抽空复习自己学习的Linux下的shell脚本知识点 1.数据类型 学习一门语言,比较关心其数据的表示方式,以及数据的类型,这里首先看一个bash shell的脚本 执行脚本如下, 由此得出以下结论: shell中,所有的变量字面类型都是字符串:仅当变量值全部由数字(0-9)组成时,才可以对变量进行数学运算 注:shell中,可通过declear或者typeset内部命令显式声明数据类型 #declare -i var //声明变量var为整型数 #declar…
shell script 入门 在 shell script 注意必须使用完全相同写在下面: 1.  指令的运行是从上而下.从左而右的分析与运行: 2.  指令的运行就如同第五章内提到的: 指令.选项不參数间的多个空白都会被忽略掉: 3.  空白行也将被忽略掉,并且 [tab] 按键所推开的空白相同规为空格键: 4.  假设读取到一个 Enter 符号 (CR) .就尝试開始运行该行 (或该串) 命令: 5.  至亍假设一行的内容太多,则能够使用『 \[Enter] 』来延伸至下一行. 6. …
Shell script fails: Syntax error: “(” unexpected google 一下. http://unix.stackexchange.com/questions/45781/shell-script-fails-syntax-error-unexpected The script does not begin with a shebang line, so the kernel executes it with /bin/sh. On Ubuntu, /bi…
shell script测试命令(test) test命令 检查系统上面某些文件或者相关的属性 常用选项 test -e :检查该文件名是否存在 例:检查/dmtsai是否存在 [root@localhost scripts1]# test -e dmtsai && echo "exist" || echo "not exist" not exist 注:检查系统中是否存在 dmtsai这个文件,存在则输出exist不存在则输出not exist t…
菜鸟教程Shell script学习笔记(下) 以下内容是学习菜鸟教程之shell教程,所整理的笔记 菜鸟教程之shell教程:http://www.runoob.com/linux/linux-shell.html Shell流程控制 和Java.PHP等语言不一样,sh的流程控制不可为空,如(以下为PHP流程控制写法): <?php if (isset($_GET["q"])){ search(q); } else { //不做任何事情 } #在sh/bash里不可以这么写,…
菜鸟教程Shell script学习笔记(中) 以下内容是学习菜鸟教程之shell教程,所整理的笔记 菜鸟教程之shell教程:http://www.runoob.com/linux/linux-shell.html Shell基本运算符 注意: 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 expr,expr 最常用. expr 是一款表达式计算工具,使用它能完成表达式的求值操作. #!/bin/bash val=`expr 2 + 2` echo "两个数之…
菜鸟教程之学习Shell script笔记 以下内容是,学习菜鸟shell教程整理的笔记 菜鸟教程之shell教程:http://www.runoob.com/linux/linux-shell.html Shell简介 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 既是一种命令语言,又是一种程序设计语言. Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务. Shell脚本(shell script),是一…
How to Create a First Shell Script   Shell scripts are short programs that are written in a shell programming language and interpreted by a shell process. They are extremely useful for automating tasks on Linux and other Unix-like operating systems.…
continue — Skip to the next iteration of a loop in a shell script…
Shell简介 Shell是一个命令解释器,它是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务.Shell在操作系统的最外层,负载直接与用户对话,把用户的输入解释给操作系统,并处理各种各样的操作系统的输出结果,输出到屏幕并返回给用户.这种对话方式可以是交互的方式(从键盘输入命令,可以立即得到shell的回应),或非交互式(执行脚本程序)的方式. Shell Shell 既是一种命令语言…
ref: https://stackpointer.io/script/how-to-catch-ctrl-c-in-shell-script/248/   #!/bin/sh # this function is called when Ctrl-C is sent function trap_ctrlc () { # perform cleanup here echo "Ctrl-C caught...performing clean up" echo "Doing cl…
解决了我一个大问题!!! http://stackoverflow.com/questions/5048112/use-gdb-to-debug-a-c-program-called-from-a-shell-script There are two options that you can do: 1) invoke GDB directly within the shell script. This would imply that you don't have standard in an…
从2005年开始,做了将近10年的系统维护,先是做网络接入管理,然后做网络安全与审计,然后做服务器管理等整个网络系统的运营管理:现在又兼着做一些Linux下的视频监控系统的软硬件维护.过程中遇到太多重复性任务,比如终端用户的管理策略下发(日志大小空间大小设置.服务启用.网络NetBIOS设置.USB设备检查.时间服务设置.补丁升级以及IPSec策略下发),Linux下的iptables及常规服务安装等,必须借助脚本来实现.当然用起来效果会相当的好,把手动10来分钟的任务使用脚本在不到1分钟就完成…
Shell script prompt to run with superuser privileges [Purpose]        Check whether have root privileges to run script   [Eevironment]        Ubuntu 16.04 bash env   [Procdeure] Source code: #!/bin/bash ]]; then echo "This script requires root privil…
Linux的shell script //编辑shell: vi a.sh //子进程运行shell sh a.sh //主线程运行shell source a.sh 相关例子: #!/bin/bash echo "hello linux!" #!/bin/bash echo "我要创建三个文件" read -p "请输入文件名:" fileuser #防止任意输入 分析文件名是否输入为空 filename=${fileuser:-"f…
Deploy Openstack all-in-one Shell Script At present(2015/10), the RDO deploment method can only install VNC console defalut, and there is no other way to config the configuration file to change to Spice like DevStack. The following script shows how t…