|grigruss 7741cea17a Create LICENSE||1 year ago|
|LICENSE||1 year ago|
|README.en.md||1 year ago|
|README.md||1 year ago|
|en.png||1 year ago|
|ru.png||1 year ago|
|screenshot.en.png||1 year ago|
|screenshot.png||1 year ago|
|watch-srv-en.sh||1 year ago|
|watch-srv.sh||1 year ago|
The script for termux (Android only), monitors the specified server. If someone has logged in to the server, the script issues a notification in the phone.
Enter termux, do the following:
apt update apt upgrade apt install termux-api
This will install updates, and establish termux communication with termux-api.
apt install git
git clone https://git.tuxnix.ru/nixscript/watch-srv
Everything is ready for configure.
Note: by default, termux has only vi, so if you are not friends with it, set the preferred one. For example, I use Midnight Commander ( mc ), which has mcedit, but I like micro more. Both mc and micro are available, so I think there are other editors too.
There are many options to leave the script in the current location, move to the system directory, for example /usr, or make the most logical. Create a ~/bin directory and copy the script there. I will describe the setup using the example ~/bin.
cp ./watch-srv/watch-srv.sh ~/bin/watch-srv.sh
Open script with our favorite editor, uncomment the last line and replace the login server.ru 22 and 0 with the required parameters.
check "login" "server.ru" 22 0
0 - is a unique identifier for the notification. Each server should be different if you monitor several. For example 0, 1, 2 ...
Generate ssh-key and upload to server
ssh-keygen cd .ssh rsync ./id_rsa.pub firstname.lastname@example.org:/home/login/.ssh/termux_key ssh email@example.com cat ~/.ssh/termux_key >>~/.ssh/authorized_keys
The last two commands will require a password. After, no password is required.
Add a task to cron. Remember, the default editor is vi. If you want to use another, here is an example:
export EDITOR="mcedit"; crontab -e # or that export EDITOR="micro"; crontab -e
The task in cron is easy to add. For example, to check every minute in the editor, we write the following line:
* * * * * ~/bin/watch-srv.sh
I decided to do a check every 30 seconds, so I had to use hack:
* * * * * ~/bin/watch-srv.sh * * * * * (sleep 30; ~/bin/watch-srv.sh)
Here are two calls to the script, both act in a minute, but the first one works, and the other with a delay of 30 seconds.
Save and exit
Now, if someone logs in on the server, a notification of this type will appear in the smartphone:
As you can see in the screenshot, there are three buttons: