Can someone help translate this snippet?

Hello all -

This snippet from a script runs on a Tru64 machine (ksh).

if ps -ef | grep thing1 | grep dtsession | grep -v grep
then
echo "Killing Thing1 desktop session"
kill -9 'ps -ef | grep thing1 | grep dtsession | grep -v grep | awk '{FS = " "}{print $2}''
fi

I'm trying to translate this and create a similar statement in a bash shell script that is running on Redhat Linux 8.0

Thank you!

All it is doing is looking for all processes where thing1 and dtsession can be identified when running "ps" and exclude the "grep" command itself.

If true (i.e. processes found matching criteria) then pass all of the process IDs to "kill". The command is expecting to find the process ID in field 2, which is parsed by "awk".

What error are you encountering?

I'm not receiving and error - I'm reading a script that was created by someone else.

I don't write very many scripts so the syntax was throwing for a loop. I understood the jist of it, but wanted to get some clarification.

I'm trying to recreate this script so that it will run on a Linux box in a bash shell.

thanks!

The script is bash compatible so that should not cause you any grief so it depends on where the ps command places the process ID. I'm fairly certain that it's in the second field in Linux distros.

Okay...

You say that this snippet is Linux compatible, but I don't think they use dtsession under the Redhat distribution.

How do you kill the session under Redhat?

Thanks!

Sorry, I wasn't trying to suggest that dtsession was a compatibility point; only that the scripting constructs were, including the usage of "ps" and "kill". I can't tell you anything about dtsession.

Thomas

dtsession is the CDE session for the user.

In linux it will be something different, like Xsession or gnome session.

To find out exactly what it is you just need to log in graphially to you linux box and us ps to see what the process is called, and substitute that for dtSession.

Not sure whether the syntax in the first line 'if' is correct.

But , even if we remove the 'if construct' and just have 'kill' command ,
it works fine.

kill -9 'ps -ef | grep thing1 | grep dtsession | grep -v grep | awk '{FS = " "}{print $2}''  2>/dev/null