Can I execute shell commands from awk? 
Author Message
 Can I execute shell commands from awk?

Hi awk pro's,

I would like to execute the kill command from within awk (awk is
launched under ksh). Can it be done?

Also, I need to pass a ksh variable into awk for maninulation, like $1.
Do I need to "quote" it?

Please copy response through e-mail, and thanks a bunch!

Dave

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 15 Mar 2003 03:00:00 GMT  
 Can I execute shell commands from awk?

Quote:
> I would like to execute the kill command from within awk (awk is
> launched under ksh). Can it be done?

I'm not so sure about old awk (as in oawk), but in all the others
(i.e. nawk, gawk, mawk etc) you can use the system function to
execute system commands. Read the manual page / documentation on
your awk to learn about the system function, but basically you'd
use it like:

system("kill "pid)

where pid is a variable holding, you guessed it, the id of the
process you are trying to kill.

Quote:
> Also, I need to pass a ksh variable into awk for maninulation, like $1.
> Do I need to "quote" it?

That depends.
The following web page:

http://www.oase-shareware.org/shell/goodcoding/awkinvoke.html

has a pretty good discussion on the ins
and outs of the different techniques for
passing shell variables to awk.

HTH,

Tristan.



Sun, 16 Mar 2003 03:00:00 GMT  
 Can I execute shell commands from awk?
This is what I've been using...in preparation for backups.  You just have to
replace the *THE USER* text with the username you'll be logging in
with...root is not effected.  Just put all this in a shell script and then
execute it.  Let me know if you have problems.

# Execute the Logoff Routine
#
#
#
# Related files:
# get.pid -> temporary list of running processes
# logoff.log -> log of people who were logged off
#
#
# remove the old get.pid file
rm get.pid
#
# get a list of active users
ps -Af > get.pid
#
# Select the PID of any user who's not a *THE USER*
# so you don't log yourself off
awk '
{if ( $10 !~ /*THE USER*/ )
 {if( $8 ~ /^login/ && $9 ~ /--/ )
  {
  system ( "kill -s 1 " $2 );
  }
 }

Quote:
}' get.pid

#
#
# END SCRIPT


Quote:
> Hi awk pro's,

> I would like to execute the kill command from within awk (awk is
> launched under ksh). Can it be done?

> Also, I need to pass a ksh variable into awk for maninulation, like $1.
> Do I need to "quote" it?

> Please copy response through e-mail, and thanks a bunch!

> Dave

> Sent via Deja.com http://www.deja.com/
> Before you buy.



Sun, 06 Apr 2003 08:28:05 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. executing a shell command within AWK

2. How do I execute a shell command and capture the standard output

3. execute shell command and store output

4. executing Shell commands

5. Help: Executing shell commands under OS X PB.

6. Executing shell commands

7. Regina can't execute shell commands under WIN 95/98SE

8. executing shell commands

9. Execute a shell command, how?

10. executing shell commands

11. Quick question: How to execute shell command inside a program

12. Problem executing shell command through tcl

 

 
Powered by phpBB® Forum Software