在shell脚本中调用另一个脚本的三种不同方法(fork, exec, source) 1、fork 调用脚本 fork ( /directory/script.sh) fork是最普通的, 就是直接在脚本里面用/directory/script.sh来调用script.sh这个脚本. 运行的时候开一个sub-shell执行调用的脚本,sub-shell...
一、删除多个文件 #!/bin/bash DATE=$(date-d-1month+%Y%m%d) #DATE=20160104 #allfile file1=autoimportdate.log file2=autoPubbjNews.log file3=autoPubdgNews.log file4=autoPublishDate.log file5=importwuxiandata.log file6=autoPublishNews.log file7...
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...