linux - Bash: Get pid of a process using a different user -
i have script in bash start java program , want pid of program after executes. pid saved in text file.
right have this:
if [ "$user" == "root" ] su $app_user -c "nohup java $java_opts >> $log_out 2>> $log_err &" su $app_user -c "echo $! > $pid_path/$cat.pid" else nohup java $java_opts >> $log_out 2>> $log_err & echo $! > "$pid_path/$cat.pid" fi
i tried doesn't work neither.
if [ "$user" == "root" ] su $app_user -c "(nohup java $java_opts >> $log_out 2>> $log_err &); (echo $! > $pid_path/$cat.pid)" else nohup java $java_opts >> $log_out 2>> $log_err & echo $! > "$pid_path/$cat.pid" fi
when run app_user works great, when run root java program starts pid file created empty.
try
su $app_user -c "nohup java $java_opts >> $log_out 2>> $log_err & echo \$! > $pid_path/$cat.pid"
\
behind $!
prevents expansion of variable, before passing su command.
Comments
Post a Comment