Multiple commands at the same time bash how to run?

I am tring to write an ash script wich can run multiple commands at the same time

Somthing like that

netcat -zvt -w 1 1-5
netcat -zvt -w 1 6-25
netcat -zvt -w 1 26-80
netcat -zvt -w 1 81-160

the scanning is pretty low 1 port at 1 second if not open so idea is to run them at the same time and then gather all the outputs

I suggest you to try gnuparallel

Check this

1 Like

Since openwrt uses busybox you can try xargs function to run multiple commands at once

1 Like

Try this, as a starting point:


netcat -zvt -w 1 1-5     > netcat1.log 2>&1 &
netcat -zvt -w 1 6-25    > netcat2.log 2>&1 &
netcat -zvt -w 1 26-80   > netcat3.log 2>&1 &
netcat -zvt -w 1 81-160  > netcat4.log 2>&1 &


cat netcat?.log

Thanks a lot :upside_down_face: ! All seams to be working
i made 16 command run at the same time and i can see in top they all got diffrent PID
9000 ports for 10 minuts wich ofcose woud take (10x16)/60 hours if it was one command
another qwestion is how to make it all i loop so i dont need to write every line for a range

1 Like

ive seen this links when i googled and tried but lack of bash knowleage it didint work for me :hot_face:

at the end i did this

rm netcat*.log
while [ $x -le 150 ]

echo "$strt -  $end"
netcat -zvt -w 1 $strt-$end  >> netcat.log 2>&1 &

  x=$(( $x + 1 ))

cat netcat.log

and it works !

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.