The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
NAWK - setting a variable to the highest value Pablo_beezo SUN Solaris 1 05-29-2008 09:29 AM
Passing shell variable to NAWK wakhan Shell Programming and Scripting 1 04-23-2008 02:52 AM
assigning nawk output to shell variable user_prady Shell Programming and Scripting 6 11-29-2007 04:01 AM
Passing a for loop variable into nawk Ant1815 UNIX for Dummies Questions & Answers 3 05-01-2007 09:56 AM
is it possible to pass external variable values to nawk? swamymns Shell Programming and Scripting 1 02-02-2006 06:13 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 10-17-2007
rakeshou rakeshou is offline
Registered User
  
 

Join Date: May 2007
Posts: 75
Unhappy How to make nawk to set a shell variable

Below is the content of the file I am parsing

Code:
bash-2.03$ cat rakesh
cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/gmon.o", errno 28, No space left on device
cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/include/README", errno 28, No space left on device
cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/include/assert.h", errno 28, No space left on device
cpio: Cannot write ", errno 28,


pkgadd: ERROR: attempt to process datastream failed
    - process </usr/bin/cpio -icdumD -C 512> failed, exit code 86
pkgadd: ERROR: unable to unpack datastream

Installation of <SMCgcc> failed (internal error).
No changes were made to the system.
Here I set the variable STATUS=5

Code:
bash-2.03$ STATUS=5

then execute this command, where I set the Shell variable STATUS=1

bash-2.03$ cat rakesh | nawk -F"," 'BEGIN{spaceError=0;}{if($2==" errno 28"){system("export STATUS=1");spaceError=1;print $0 ": ERROR"} else {print $0;}}END{if(spaceError==1)system("banner \"No space\"");}'

cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/gmon.o", errno 28, No space left on device: ERROR
cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/include/README", errno 28, No space left on device: ERROR
cpio: Cannot write "reloc/lib/gcc-lib/i386-pc-solaris2.7/2.95.2/include/assert.h", errno 28, No space left on device: ERROR
cpio: Cannot write ", errno 28,: ERROR


pkgadd: ERROR: attempt to process datastream failed
    - process </usr/bin/cpio -icdumD -C 512> failed, exit code 86
pkgadd: ERROR: unable to unpack datastream

Installation of <SMCgcc> failed (internal error).
No changes were made to the system.
#     #
##    #   ####            ####   #####     ##     ####   ######
# #   #  #    #          #       #    #   #  #   #    #  #
#  #  #  #    #           ####   #    #  #    #  #       #####
#   # #  #    #               #  #####   ######  #       #
#    ##  #    #          #    #  #       #    #  #    #  #
#     #   ####            ####   #       #    #   ####   ######
Check if STATUS got set.
Code:
bash-2.03$ echo $STATUS
5
No

The command system("export STATUS=1"); doesn't seem to work.

I want to chech if STATUS=1, If yes, I want to display a custom error message.

Please help

Thanks
  #2 (permalink)  
Old 10-18-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Perhaps just use "exit spaceError" as the last command in your awk script. Then in the shell script do "export STATUS=$?" immediately after the awk.
Closed Thread

Bookmarks

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 06:59 PM.


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