There is a file with nicknames (test.list), each word from a new line.

test stack over flow 

We need a cycle that with a certain delay will execute a series of commands in telegram-cli.

  sleep 1m echo "set_username НИК" echo "msg user text" done | /home/ubuntu/tg/bin/telegram-cli -w test.list 

Something like this, just how to start the cycle itself, so that every time a nickname is taken from a new line?

It is desirable to SH, but you can any jap.

    1 answer 1

    Apparently, something like this (if I correctly understood that your program ~/tg/bin/telegram-cli reads the commands you wrote from your stdin , executes them, and then immediately exits):

     cat test.list | while read n; do sleep 60 echo -e "set_username $n\nmsg $n text" | ~/tg/bin/telegram-cli done 

    addition

    if between the transferred lines it is necessary to insert a pause in, for example, two seconds, then you can use the { команды; } | программа { команды; } | программа { команды; } | программа :

     { echo "set_username $n"; sleep 2; echo "msg $n text"; } | ~/tg/bin/telegram-cli 

    if you need a “closer” interaction with the program being started (for example, expect the program to output some specific information to stdout and only after that send something to it to stdin ), you can use the expect program.

    • Thank you, but there is another problem. To send a message to the user, you need to find it through the search. echo "set_username $n\ncontact_search MyUSERNAME\nmsg NAME TEXT | ~/tg/bin/telegram-cli But the n echo "set_username $n\ncontact_search MyUSERNAME\nmsg NAME TEXT | ~/tg/bin/telegram-cli does not have time to execute the command contact_search MyUSERNAME and execute msg MyNAME text . Can not somehow add a 1-2 delay seconds between executing these 2 commands? Or opening a Tg-Kli terminal and simply sending 2 commands with a 1-minute delay so that the Tg session does not stop? - BoberMod
    • @BoberMod, I added an answer based on your comment. It’s better to add the information provided in your comments to the question itself (by clicking “edit” below the question text). - aleksandr barakin