Automation of bash action

For a while I played a game where there were some very annoying actions that needed to be repeated over and over again. I found a solution to this problem with bash. I’ll keep silent about the name of the game.

This is not a call now to sculpt a cloud of bots, but just a small manual on how to automate actions using bash . Usually used on Linux.

So, in this task it was necessary to collect 17 parts.
To collect them, you first had to press “Enter”, then wait 6 seconds until the download bar reaches the end and press “Enter” again. After that, we wait 11 seconds and you can start in a new circle.

To send the keystroke, we will use xdotool . For different systems, it is put in different ways, I will not focus on this.

Create a file with the name, for example, autosbor.sh and open its editing.
I have Debian, so I use the nano command:
nano autosbor.sh
First, declare the variables.

#!/bin/bash
declare -ia=17 #reps
declare -ii=1 #counter. Do not touch
declare -ip=1 #step

The declare function is needed just for declaring variables. The -i option indicates that this variable will be of type integer (numeric).
The counter is a variable that we will increase in the loop.
Threshold – how much to add. There was a time when I also needed to output numbers to the console during the execution process.

Next, I added a pause in the script in order to manage to switch to the desired window. It was possible to make the window change by its ID, but found this a bit inconvenient.

sleep 5
Well, in the end the cycle itself. Before a pause in the cycle, the main thing is not to forget to put an increase in the counter variable, otherwise the cycle will end up infinite.

while [ $a != $i ]
do
xdotool key Return
sleep 6
xdotool key Return
i=$(($i+$p))
sleep 11
done

The key argument is a keystroke on a keyboard. Return – the Enter key itself.

Actually everything. You can give the script the right to execute:
chmod + x autosbor.sh
And run:
./autosbor.sh