參考:
https://blog.csdn.net/sdb5858874/article/details/80522129
https://blog.csdn.net/ruiyelp/article/details/80184249
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