How to get pid of su --session-command file thats ran on there

SSpoke

This line ran in a script

su --session-command="$javaCommandLine & >>$serviceLogFile 2>&1 & echo \$! >$pidFile" $serviceUser || return 1
pid="$(<$pidFile)"
echo $pid

The Pid is increased by one from the Pid the program ran by su really is.
How I do I get that program's pid?

SSpoke

I got a answer from serverfault stackexchange. by Daniel t. @ https://serverfault.com/questions/563087/sh-bash-script-ambiguous-redirect-pid-of-file-using-single-quotes

Quoted:

The process ID is off by one because you have put an extra & after the $javaCommandLine. In other words, you have put two processes in the background before calling echo $!, thus getting the PID of >>$serviceLogFile 2>&1 rather than $javaCommandLine. Those two pieces should be put in one, as the old 2 line codes shows

 su --session-command="$javaCommandLine & >>$serviceLogFile 2>&1 & echo \$! >$pidFile" $serviceUser || return 1

You might need to change it to -

 su --session-command="$javaCommandLine >>$serviceLogFile 2>&1 & echo \$! >$pidFile" $serviceUser || return 1

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the user profile info thats associated with the user session ID?

From Dev

How to get the dir name where I ran the command

From Dev

How to know PID of the process ran by remote ssh

From Dev

How to get PID from remote executed command?

From Dev

How to get PID from remote executed command?

From Dev

How do I get the path of the file a Python program was ran with (Windows)?

From Dev

how to read a file thats comma‐delimited

From Dev

how to read a file thats comma‐delimited

From Dev

How to get width of Popup thats in the ComboBox template

From Dev

how to get routes thats in a middleware in laravel 5.1

From Dev

How to get width of Popup thats in the ComboBox template

From Dev

How do I target a Load Balancer with a terminal command ran on another minion via a .sls file in saltstack?

From Dev

how to know pexpect command actually ran?

From Dev

How to get pid of process executed with system() command in c++

From Dev

How can I get the cpu% usage of a Windows Pid on the command line?

From Dev

Bash - how to write the output of a command into a variable and also get the commands pid

From Dev

How to get the pid of the last executed command in shell script?

From Dev

How do I get the first branch PID of an application in pstree command?

From Dev

Bash - how to write the output of a command into a variable and also get the commands pid

From Dev

Get the PID of file creation

From Dev

How to get STDERR in Perl from a command executed in pipe with su -c

From Dev

Get command PID and send to another

From Dev

How to take information thats entered into a entry box and save it in a text file

From Dev

how do you write a file in java to desktop thats platform friendly?

From Dev

How to get a reference to RDD thats already persisted in memory?

From Dev

How would I see if a certain Batch File is running and get the PID?

From Dev

Get the PID of a remote SSH Session [QNX]?

From Dev

How can I get pid and its executable path information through the file which is executed by this pid?

From Dev

How can I get pid and its executable path information through the file which is executed by this pid?

Related Related

  1. 1

    How to get the user profile info thats associated with the user session ID?

  2. 2

    How to get the dir name where I ran the command

  3. 3

    How to know PID of the process ran by remote ssh

  4. 4

    How to get PID from remote executed command?

  5. 5

    How to get PID from remote executed command?

  6. 6

    How do I get the path of the file a Python program was ran with (Windows)?

  7. 7

    how to read a file thats comma‐delimited

  8. 8

    how to read a file thats comma‐delimited

  9. 9

    How to get width of Popup thats in the ComboBox template

  10. 10

    how to get routes thats in a middleware in laravel 5.1

  11. 11

    How to get width of Popup thats in the ComboBox template

  12. 12

    How do I target a Load Balancer with a terminal command ran on another minion via a .sls file in saltstack?

  13. 13

    how to know pexpect command actually ran?

  14. 14

    How to get pid of process executed with system() command in c++

  15. 15

    How can I get the cpu% usage of a Windows Pid on the command line?

  16. 16

    Bash - how to write the output of a command into a variable and also get the commands pid

  17. 17

    How to get the pid of the last executed command in shell script?

  18. 18

    How do I get the first branch PID of an application in pstree command?

  19. 19

    Bash - how to write the output of a command into a variable and also get the commands pid

  20. 20

    Get the PID of file creation

  21. 21

    How to get STDERR in Perl from a command executed in pipe with su -c

  22. 22

    Get command PID and send to another

  23. 23

    How to take information thats entered into a entry box and save it in a text file

  24. 24

    how do you write a file in java to desktop thats platform friendly?

  25. 25

    How to get a reference to RDD thats already persisted in memory?

  26. 26

    How would I see if a certain Batch File is running and get the PID?

  27. 27

    Get the PID of a remote SSH Session [QNX]?

  28. 28

    How can I get pid and its executable path information through the file which is executed by this pid?

  29. 29

    How can I get pid and its executable path information through the file which is executed by this pid?

HotTag

Archive