Houssem
Houssem

Reputation: 23

"Resource temporarily unavailable" when using Awk and Fork

I wrote a script that it takes a csv file and replace the third column with the HASH of the second column with some string (Key). After 256 rows, I got an error

awk: cmd. line:3: (FILENAME=C:/hanatest/test.csv FNR=257) fatal: cannot create child process for `echo -n E5360712819A7EF1584E2FDA06287379FF5CC3E0A5M7J6PiQMaSBut52ZQhVlS4 | openssl ripemd160 | cut -f2 -d" "' (fork: Resource temporarily unavailable)

I change the CSV file and I got always the same error after 256 rows.

here is my code:

awk -F "," -v env_var="$key" '{
    tmp="echo -n "$2env_var" | openssl ripemd160 | cut -f2 -d\" \""
tmp | getline cksum
$3=toupper(cksum)
print
}' //test/source.csv > //ziel.csv

Can you please help me ?

Here my sample input:

25,XXXXXXXXXXXXXXXXXX,?
44,YYYYYYYYYYYYYYYYYY,?
84,ZZZZZZZZZZZZZZZZZZ,?

and here my expected output:

25,XXXXXXXXXXXXXXXXXX,301E2A8BF32A7046F65E48DF32CF933F6CAEC529
44,YYYYYYYYYYYYYYYYYY,301E2A8BF32A7046F65E48EF32CF933F6CAEC529
84,ZZZZZZZZZZZZZZZZZZ,301E2A8BF32A7046F65E48EF33CF933F6CAEC529

Thanks in advance

Upvotes: 1

Views: 1056

Answers (1)

Ed Morton
Ed Morton

Reputation: 203684

Let's make your code more robust first:

awk -F "," -v env_var="$key" '{
    tmp="echo -n \047" $2 env_var "\047 | openssl ripemd160 | cut -f2 -d\047 \047"
    if ( (tmp | getline cksum) > 0 ) {
        $3 = toupper(cksum)
    }
    close(tmp)
    print
}' /test/source.csv > /ziel.csv

Now - do you still have a problem? If you're considering using getline make sure to read and fully understand the correct uses and all of the caveats discussed at http://awk.freeshell.org/AllAboutGetline.

Upvotes: 3

Related Questions