The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to achicve translate in unix javeed7 Shell Programming and Scripting 1 03-31-2008 12:05 PM
Translate Toolkit 1.1.1 (Default branch) iBot Software Releases - RSS News 0 03-27-2008 09:50 AM
Apama CEP Code Snippet iBot Complex Event Processing RSS News 0 02-12-2008 01:20 AM
Trouble with UNIX tr (translate) function by_tg UNIX for Dummies Questions & Answers 2 01-30-2008 07:23 PM
translate text (1 position) with sed peterk Shell Programming and Scripting 5 12-12-2003 05:31 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-24-2005
Heron Heron is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 10
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!
  #2 (permalink)  
Old 03-24-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by Heron
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
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?
  #3 (permalink)  
Old 03-24-2005
Heron Heron is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 10
Quote:
Originally Posted by tmarikle
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!
  #4 (permalink)  
Old 03-24-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by Heron
I'm trying to recreate this script so that it will run on a Linux box in a bash shell.
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.
  #5 (permalink)  
Old 03-24-2005
Heron Heron is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 10
Quote:
Originally Posted by tmarikle
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!
  #6 (permalink)  
Old 03-28-2005
tmarikle tmarikle is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2005
Posts: 683
Quote:
Originally Posted by Heron
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?
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
  #7 (permalink)  
Old 03-29-2005
bhargav's Avatar
bhargav bhargav is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2004
Location: USA
Posts: 511
Quote:
Originally Posted by Heron
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!

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.

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

Closed Thread

Bookmarks

Tags
linux

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0