No Description

grigruss 7741cea17a Create LICENSE 1 year ago
LICENSE 7741cea17a Create LICENSE 1 year ago
README.en.md cb3a673dc1 Added support for multiple servers 1 year ago
README.md c0b6c3800c Обновить 'README.md' 1 year ago
en.png 5d49bfaabe add links en-ru to README 1 year ago
ru.png 5d49bfaabe add links en-ru to README 1 year ago
screenshot.en.png a4324ca8c6 add english screenshot 1 year ago
screenshot.png a5e3c78ea6 add screenshot 1 year ago
watch-srv-en.sh cb3a673dc1 Added support for multiple servers 1 year ago
watch-srv.sh cb3a673dc1 Added support for multiple servers 1 year ago

README.en.md

watch-srv

Language RUS

Build Status

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.

ScreenShot

Updates

  1. Added support for multiple servers.
  2. Attention: Now it is necessary to specify the notification-id, the fourth parameter. Any numeric value that is not repeated on other servers.

  1. Install
  2. Configuration
  3. Resume

Requirements

  1. termux, termux-api
  2. Permissions termux and termux-api to access the network and files.
  3. Generate ssh-key to access the server without a password.

Installation

  1. Install termux
  2. Install termux-api
  3. Enter termux, do the following:

    apt update
    apt upgrade
    apt install termux-api
    

    This will install updates, and establish termux communication with termux-api.

  4. Install git

    apt install git
    
  5. Clone watch-srv

    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.

Configuration

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.

  1. Make directory

    mkdir ~/bin
    
  2. Copy script

    cp ./watch-srv/watch-srv.sh ~/bin/watch-srv.sh
    
  3. 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 ...

  4. Generate ssh-key and upload to server

    ssh-keygen
    cd .ssh
    rsync ./id_rsa.pub login@server.ru:/home/login/.ssh/termux_key
    ssh login@server.ru cat ~/.ssh/termux_key >>~/.ssh/authorized_keys
    

    The last two commands will require a password. After, no password is required.

  5. 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

  6. Run cron

    crond
    

    Now, if someone logs in on the server, a notification of this type will appear in the smartphone:

ScreenShot

As you can see in the screenshot, there are three buttons:

  1. All right - prevents the permanent notification to appear until the user logs out on the server. After all users have logged out, the script runs in standard mode.
  2. Copy - puts the notification text into the smartphone's system clipboard.
  3. Get full log - gets the whole log and saves it to Downloads/srv-login.log

Resume

Everything is quite simple. If you have any suggestions, suggestions, ideas, write to VK@Nixscript or to me FB@grig.russ Instagram@grigruss e-mail.