How to make nawk to set a shell variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to make nawk to set a shell variable
# 1  
Old 10-17-2007
Data 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  
Old 10-18-2007
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to pass nawk variable to shell within the same script?

Hi All, I tried googling but so far no luck, can someone tell me how pass the variable value used inside the nawk command to shell. In the below script i get the value of $c (without color: Total Executed: " c ") but the printf which is outside the nawk command doesn't print the value or it... (4 Replies)
Discussion started by: Optimus81
4 Replies

2. Shell Programming and Scripting

set variable with square brackets in c shell!

Hi Guys, I want to set a variable which happend to have square brackets in them. I tried multiple ways that is by escaping it with quotes (both single and double ) but it didn't help. All I want is: set x = slicearray.slice\.post My failed attempts were: set x = "slicearray.slice\.post"... (3 Replies)
Discussion started by: dixits
3 Replies

3. Shell Programming and Scripting

Set shell variable from command

shell script has a command inside back quotes in method update_TABLE I need to store the count of number of Rows updated and store it in shell script variable "num" num = 0; Update_TABLE Update_TABLE() { `echo " set verify off feedback off echo off pagesize 0 head off... (4 Replies)
Discussion started by: finder255
4 Replies

4. Shell Programming and Scripting

how to set/get shell env variable in python script

greetings, i have a sh script that calls a python script. the sh script sets an env variable BIN: export BIN=bin64i need to get that BIN variable's value and use it within this python script. anyone know how to do this? thanx in advance. (5 Replies)
Discussion started by: crimso
5 Replies

5. Shell Programming and Scripting

Set/Export Env Vars from with Shell Script With Input Variable

I have a shell script I want to run that will set environment variables based on the value of an input variable submitted when the shell script is called. For example: $ mgenv.sh prod This would set environment variables for prod $ mgenv.sh test This would set environment variables... (1 Reply)
Discussion started by: brtaylor73
1 Replies

6. Shell Programming and Scripting

Passing shell variable to NAWK

I am trying to make a simple script in which i take input from shell and then forward the value to nawk (BEGIN). but when i run below mention script so it give no output. echo "Enter TRUNK GROUP:" read TGR cat /omp-data/logs/5etr/080422.APX | nawk -F"|" -v P=$TGR ' BEGIN { TG=P;... (1 Reply)
Discussion started by: wakhan
1 Replies

7. Shell Programming and Scripting

set variable with another variable? c shell

okay, this shouldn't be difficult but I can't figure it out. How can I set a variable with another variable. I have the following: foreach pe ($dir $sp) set tpe = `echo $pe | grep M` if ($tpe == M) then set ${$pe} = M <--- This doesn't work else endif end In this case what... (2 Replies)
Discussion started by: wxornot
2 Replies

8. Shell Programming and Scripting

assigning nawk output to shell variable

Hello friends, I doing the follwing script , but found problem to store it to a shell variable. #! /bin/sh for temp in `find ./dat/vector/ -name '*.file'` do echo $temp nawk -v temp=$temp 'BEGIN{ split(temp, a,"\/"); print a}' done output: ./dat/vector/drf_all_002.file... (6 Replies)
Discussion started by: user_prady
6 Replies

9. Shell Programming and Scripting

problem in getting the path of environment variable set in bashrc in my shell script

hi all i have joined new to the group. i have set an variable in my bashrc file. .bashrc PROGHOME=/home/braf/braf/prog export PROGHOME but while using it in my shell script its path is not taken and i had to explicitly give the export command to set the path. in my script... (8 Replies)
Discussion started by: krithika
8 Replies

10. Shell Programming and Scripting

Set Path variable in c shell

I set my path environment variable in c shell, using the syntax below setenv PATH "${PATH}:/usr/local:/usr/local/bin" and placed this in $HOME/.login $HOME/.cshrc and /etc/.login /etc/.cshrc but when I issued echo $PATH or set command the output does not reflect changes made to... (5 Replies)
Discussion started by: hassan2
5 Replies
Login or Register to Ask a Question