1
cat /export/home/tmp/name_file.txt|while read line
do
        run -i name_file.tx $line  > /dev/null 2>&1
        address name_file.txt $line > /dev/null 2>&1
        sleep 1
done
2

If you just want to run the code snippet in your question five times in the background, then one easy way of doing that is putting the code into a file, script.sh, and executing it as a background job from a loop five times:

Assuming that you're using bash or ksh93:

$ for i in {1..5}; do ./script.sh & done

That would be the easiest way.

Of course, the loop may go in the script itself:

#!/bin/ksh

for i in {1..5}; do
    cat /export/home/tmp/name_file.txt|while read line
    do
            run -i name_file.tx $line  > /dev/null 2>&1
            address name_file.txt $line > /dev/null 2>&1
            sleep 1
    done &
done

Here's an alternative, the way I would have written it:

#!/bin/ksh

for i in {1..5}; do
    while read -r name
    do
        run -i name_file.txt "$name"
        address name_file.txt "$name"
        sleep 1
    done </export/home/tmp/name_file.txt >/dev/null 2>&1 &
done 
  • I'm sorry Ieft this out.. ( #!/bin/ksh) So do I just remove everything else and use this only $ for i in {1..5}; do ./script &; done or do I add it to what i shared – suaveaz Feb 16 '17 at 0:03
  • I'm new to this so excuse me for my questions if it does not make sense to you. I have created a file called name_file and I just want this to run 5 instances. Where do I add this in the script or do I not? $ for i in {1..5}; do ./script &; done – suaveaz Feb 16 '17 at 0:54
  • #!/bin/ksh cat /export/home/tmp/name_file.txt|while read line do run -i name_file.tx $line > /dev/null 2>&1 address name_file.txt $line > /dev/null 2>&1 sleep 1 done – suaveaz Feb 16 '17 at 0:54
  • @suaveaz Sorry for the late reply, I had to sleep for a while. I have updated the answer. – Kusalananda Feb 16 '17 at 7:50
  • I'm getting this error..../transGen[3]: syntax error at line 9 : `name_file' unexpected Is it because, I'm using transGen? – suaveaz Feb 16 '17 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.