Answer the question
In order to leave comments, you need to log in
how to create a loop with execution after the completion of the command?
I apologize for a simple and stupid question
, there is a piece of iron with 3g, located in a remote corner. knowing the stability of our mobile Internet - the connection can sometimes break
to the piece of iron, constant access is needed
for this, a reverse shell is created via ssh
ssh -R localhost:2222:localhost:22 [email protected]
in bashscripting, I'm completely zero and unfortunately there is no time to figure it out , I
think you need a cycle with the execution of this command. how to make it run in case of disconnect?
thank you in advance
Answer the question
In order to leave comments, you need to log in
autossh
Holds an additional connection over which it sends a Keep-alive for verification. Available in ubuntu and debian repositories
In general:
while :
do
ssh -R localhost:2222:localhost:22 [email protected]
done
As far as I remember, there is inittab. Write there something like
tn:2345:respawn:/usr/bin/ssh -n -R localhost:2222:localhost:22 [email protected]
cat > /usr/bin/connect-somewhere.sh
#!/bin/bash
while :; do ssh -R localhost:2222:localhost:22 [email protected]; date; sleep 20; done
chmod +x /usr/bin/connect-somewhere.sh
And in /etc/crontab:
* * * * * root flock -n /var/lock/somelock.lock -c /usr/bin/connect-somewhere.sh
Run and don't sweat it. An open ssh session will prevent the loop from continuing. When the session falls off due to a timeout, the script will display the date (of course, it is better in the log), wait 20 seconds, and try to connect again. Cron won't let that thing die.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question