0

I'm about to test performance of a server which can service multi-clients simultaneously.

Therefore, I'm writing a shell script to execute multiple processes (many clients runs at the same time). When the client ask for input from prompt, I don't know how to pass value to client in shell script in this case.

Please give me some ideas to solve this, I don't have much experience with shell script. Thank you.


In case you can't access the link, here is the .c source code of client where it needs input from user:

    /*prompt the user to enter data*/
    printf("Enter a : ?\n"); // When the client runs here, I don't know how to give it a value from shell script
    scanf("%u", &client_data.a);
    printf("Enter b : ?\n");
    scanf("%u", &client_data.b);
dustin2022
  • 182
  • 2
  • 18
  • 2
    What do you mean by "run multiple clients"? What kind of clients are you running? It sounds like you should be using Expect. – Barmar Jun 28 '22 at 04:50
  • 1
    Have a look at [expect](https://linux.die.net/man/1/expect). It can be used to send messages to programs waiting for user input on stdin. You chances of getting an answer here would probably be higher if you could formulate your question in a more specific way. – Dima Chubarov Jun 28 '22 at 04:53
  • What kind of service do you want to stress? if it is a web or rest api , there are another easy strategies for that – JRichardsz Jun 28 '22 at 05:48
  • You are reading from stdin, so you can just send the test data to your program via stdin. BTW: Make sure that you are sending very long input data, so you can witness the crashing of your program due to buffer overrun.... – user1934428 Jun 28 '22 at 06:38
  • @DmitriChubarov if I use expect, it seems like my script will become tcl script, not bash script anymore. – dustin2022 Jun 30 '22 at 03:40
  • Shell scripts by their very nature combine tools written in many languages. The fact that `expect` is implemented in TCL is no more and no less relevant than that `cat` is probably written in C and `ag` in Perl (IIRC). – tripleee Jul 09 '22 at 12:25
  • A much better design anyway is to change the C program so that it can receive input programmatically, perhaps via an environment variable if you don't want to parse command-line arguments. – tripleee Jul 09 '22 at 12:43

0 Answers0