当前位置: 代码迷 >> 综合 >> NO1:sh脚本书写和后台运行,查看JAVA_HOME路径
  详细解决方案

NO1:sh脚本书写和后台运行,查看JAVA_HOME路径

热度:59   发布时间:2024-01-29 20:19:51.0

sh脚本,后台运行:
执行脚本test.sh:./test.sh

更改sh脚本权限:chmod u+x *.sh

直接在后台运行脚本test.sh:./test.sh &


不中断的在后台运行test.sh:nohup ./test.sh &(test.sh的打印信息会输出到当前目录下的nohup.out中)
不中断的在后台运行test.sh另一个命令:setsid ./test.sh &

使用ps -ef |grep test.sh可查看到正在运行的test.sh脚本进程

脚本:vi test.sh

#!/bin/bash

cd ./bin/
pwd
echo "start flume"
./flume-ng agent --conf conf --conf-file ../conf/test1.conf --name a1 -Dflume.root.logger=INFO,console

查看JAVA_HOME路径
执行which java

[root@localhost ~]# which java 
/usr/bin/java 
执行ls -lrt /usr/bin/java

[root@localhost ~]# ls -lrt /usr/bin/java 
lrwxrwxrwx. 1 root root 22 10月 10 08:06 /usr/bin/java -> /etc/alternatives/java 
执行ls -lrt /etc/alternatives/java

[root@localhost ~]# ls -lrt /etc/alternatives/java 
lrwxrwxrwx. 1 root root 73 10月 10 08:06 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64/jre/bin/java 
由上可知java的路径为: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64,进入该路径查看文件如下:

[root@localhost ~]# cd /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64 
[root@localhost java-1.8.0-openjdk-1.8.0.144-0.b01.el7_4.x86_64]# ll 
总用量 4 
drwxr-xr-x. 2 root root 4096 10月 10 14:53 bin 
drwxr-xr-x. 3 root root 132 10月 10 14:53 include 
drwxr-xr-x. 4 root root 28 10月 10 08:03 jre 
drwxr-xr-x. 3 root root 144 10月 10 14:53 lib 
drwxr-xr-x. 2 root root 204 10月 10 14:53 tapset