Sponsored Content
Top Forums Shell Programming and Scripting Pass parameters to a function and running functions in parallel Post 302875225 by neutronscott on Tuesday 19th of November 2013 03:32:24 AM
Old 11-19-2013
Quote:
Originally Posted by Ravindra Swan
Please check where am i going wrong.
full_refresh.txt: input file
here i tried using split command to read 4 lines at once.
Well, quite possibly a lot. Is this for POSIX sh? If you have bash, you could use arrays instead of eval.

You should quote every "$variable".

You can test a command, rather than assign "$?" to a variable and test the variable... if takes a command ...

You should read your fields into separate values using read instead of `echo "$line" | awk '...'` ...

You write a "list.txt" but read a "list"

Taking all this into account, plus I don't think we need "split", I rewrite it as so:

Code:
#!/bin/sh
file='full_refresh.txt'
schema=schema
table=table
nickname=nickname

# i don't have this function...test
db2() {
        echo "db2: $@"
        #pretend like it takes some time
        sleep 10
}

full() {
        echo "You entered full $1,$2,$3"
        if db2 "call util.DATA_REFRESH('LOAD','$1','$2','$3','$2','R','?',?)"; then
                echo "$1.$2" >>Success_list.txt
        else
                echo "$1.$2" >>failure_list.txt
        fi
}

while IFS='|' read schema table nickname _; do
        count=$((count+1))
        full "$schema" "$table" "$nickname" &
        if [ "$count" -ge 4 ]; then
                wait
                count=0
        fi
done < "$file"

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

passing command line parameters to functions - sh

All, I have a sh script of the following tune: function a () { #functionality.. } function b () { #functionnlity.. } function check () { # this function checks for env and if all fine call build } function usage () { #sh usage details } function build () { #calls either a or b or... (5 Replies)
Discussion started by: vino
5 Replies

2. Shell Programming and Scripting

Run a same script in parallel with diffs parameters

i have script say some_script.ksh that takes an argument I need to run some_script.ksh in background parallely at the sametime with different arguments. Once all the background jobs complete, i need to run this script again in parallel with another 5 set of arguments. Would really... (1 Reply)
Discussion started by: hyennah
1 Replies

3. Shell Programming and Scripting

Get the List of functions with modified parameters

Hi I have 2 files a.c and a.bak where I changed long to int using awk script. I want to get the list of functions whose parameters got modified for eg: fun ( long a, long b ) might be changed to fun ( int a, int b ) (1 Reply)
Discussion started by: Sivaswami
1 Replies

4. Shell Programming and Scripting

Handling parameters in Shell Functions

Hi, Please help me with the below situation where I have to handle the parameters passed to a function in a unique way. Below is the code, which I am trying to execute. I basically want to pass the parameter to a function, where I am trying to get user input into array(s). I want to name... (7 Replies)
Discussion started by: bharath.gct
7 Replies

5. Shell Programming and Scripting

Pass parameters to function

Hi, for example I have this function: function get_param () { test=echo "some string" test2=echo "someother string" } I want to call this function and get test or test2 result, how do I do that ? Thank you (2 Replies)
Discussion started by: ktm
2 Replies

6. Shell Programming and Scripting

Calling multiple functions in parallel

Hello, I have multiple functions within a shell script. eg. function_database_backup, unix_tar_creation, etc. I would like to run these functions in parallel, as each is independent of the other. If these were simple commands, I could have probably run each of the commands in background. ... (1 Reply)
Discussion started by: neil.k
1 Replies

7. Shell Programming and Scripting

How to execute functions or initiate functions as command line parameters for below requirement?

I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line if then... (8 Replies)
Discussion started by: saku
8 Replies

8. Shell Programming and Scripting

Parallel processing for functions in xargs

I have a script (ksh) which tries to run a function in parallel for performance gains. I am also trying to limit the number of parallel child processes to avoid overloading the system by using a variable to count triggered processes and waiting for completion e.g. do_something () { ... } ... (9 Replies)
Discussion started by: jawsnnn
9 Replies

9. Shell Programming and Scripting

Python passing multiple parameters to functions

Hi, I am a beginner in python programming. In my python script have a main function which calls several other functions. The main function gets its input by reading lines from a input text file. I call the main function for every line in input text file through a loop. def main(line): var1... (6 Replies)
Discussion started by: ctrld
6 Replies

10. Shell Programming and Scripting

How to pass subject,mailbody and filename as parameters to function?

Hi Experts, how to pass subject,mailbody and filename as parameters to function. mode=$1 file=/db/files/uniq.txt mail_send() { export MAILPART=$(uuidgen) export MAILPART_BODY=$(uuidgen) { echo "TO:nalu.d@hes.com" echo "Subject:$subject" echo "MIME-Version: 1.0" ... (0 Replies)
Discussion started by: nalu
0 Replies
ypmatch(1)						      General Commands Manual							ypmatch(1)

NAME
ypmatch - print the values of one or more keys from a NIS map SYNOPSIS
ypmatch [ -kt ] [ -d domain ] key ... mapname ypmatch -x DESCRIPTION
ypmatch prints the values of one or more keys from the NIS database specified by mapname, which may be a map name or a map nickname. OPTIONS
-d domain Specify a domain other than the default domain as returned by domainname(8). -k Display map keys. This option is useful with maps in which the values are null or the key is not part of the value. -t This option inhibits map nickname translation. -x Display the map nickname translation table. FILES
/var/yp/nicknames map nickname translation table. SEE ALSO
domainname(8), nicknames(5), ypbind(8), ypcat(1), yppoll(8), ypserv(8), ypset(8), ypwhich(1) AUTHOR
ypmatch is part of the yp-tools package, which was written by Thorsten Kukuk <kukuk@linux-nis.org>. YP Tools 2.14 April 2010 ypmatch(1)
All times are GMT -4. The time now is 03:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy