var=$(ps-ef|grep-vgrep|grephello|awk{print$2}) #其中的grep-vgrep就是获取指定外的元素,awk的$0是所有值,而$1,$2就是他的域 注意使用ps-ef查出来的第一列是用户名第二列是pid第三列是ppid 我们获得了pid后可以来杀死进程 **************kill相关信息***...
#!/bin/bash JAVA_HOME=/usr/local/jdk1.7/jdk1.7 TOMCAT_HOME=/usr/local/tomcat/apache_tomat-8 exportJAVA_HOME usage={stop|start|restart} start_tomcat=$TOMCAT_HOME/bin/startup.sh stop_tomcat=$TOMCAT_HOME/bin/shutdown.sh #lookpidisexists #THIS...
#!/bin/sh arg1=$1 arg2=$2 tellname() { echothisistellnamefuncitonandexecutethisfunctiontellname! echotwoargs:$arg1,$arg2 } echoexecutefunction #executefunction tellname 其中的$1 就是表示获取的第一个参数 $2 就是获取的第二个参数,之后还会看...
其中的$LOGNAME 就是获取登陆的用户名(注意这里的LOGNAME 是区分大小写的) #!/bin/bash #ifuserisrootreboldelsechangetorootthanrebold user=$LOGNAME echo$user if[$user=root] then echouserisrootrebortsystem init6 else echo$userend exit1 fi...
文章主要用到了$() 反引号`` 以及 $1,$2 $0 ,$# 等这些特殊符号 1、 #!/bin/sh #name:testlinuxshell #通过pwd命令获取路径,然后在判断是不是目录, #下面的这个命令可以写成两个反引号``和$()是同样的功能 File=$(pwd) echo$File if[$File=/] then echothi...
文章只要是 简单介绍 if 的用法 以及其中涉及到的 /dev/null 无底洞和 2 1 的介绍 1、 [plain]view plaincopy print? #!/bin/sh #name:testlinuxshell #标准输入,获取从键盘输入的数据 readname #判断是否为空还可以使用-z$name如果成立则空 #-s$name判断不...
1、 #!/bin/sh #name : test linux shell FILE=./Tlinux.sh echo $FILE if [ -x $FILE ] then echo $FILE can execute else echo $FILE can not execute fi 2、 使用 -a #!/bin/bash # file=test if [ -r $file ] then if [ -r $file -a -w $file ] then ech...
我们在服务器上经常能看到很多复制,启动停止程序的脚本,下面就来慢慢学学 菜鸟一枚如有错误还请大家指教 一、文件状态的测试 1、文件状态有: -d(directory):目录 -L(link): 符号链接 -f (file): 正规文件 -r (read) 可读 -w (write) : 可写 -x(ecexu...
在linux中,利用Shell的作业控制是比较常用的操作,在这一节中我们将探究作业控制相关的操作。为了方便我们查看区分不同的进行,我们编写如下程序,其功能是每间隔2秒输出一次自己的编号。 1 /* 2 ** Test puting a running program into backgound 3 */ 4 #i...
(本来7年前就开始写过Shell脚本,不过最近写一段bash脚本时,感觉要用下数组,忽然发现不知道一些语法细节,所以记录一下吧) 在Shell中(我这里是Bash),其实没有传统意义上的数据类型,把任何变量中存的值都是作为字符组成的字符串。当然,通过declare可...