пятница, 25 октября 2019 г.

Remote connect to Linux Mint by RDP

Иногда возникает необходимость подключиться к удаленной системе, работающей на Linux Mint.

Вариантов несколько - SSH с консолью и пробросом графики, VNC, TeamViewer, и RDP.

В зависимости от задач и возможностей (открытые порты и настройки), можно воспользоваться вышеуказанными приложениями и протоколами.



Читая недавно статью на Хабре по переходу разработчика с Windows на Linux, обратил внимание на рецепт подключения к удаленному хосту с Linux Mint по RDP.
Привожу его здесь.

После настройки программ на рабочей машине встал вопрос настройки удаленных сеансов.
В силу ограничений офисного файрвола vnc использовать было нельзя т.к. порт 5900 был закрыт, а проверять другие какие доступны было лениво. Коллеги подсказали, что можно использовать xrdp, который работает на стандартом rdp порте и подключаться к нему можно с любого клиента: хоть на windows машинах, хоть на Linux. Но как выяснилось не все так безоблачно. При попытке входа в rdp я видел только черный экран после ввода своих учетных данных в окне авторизации. Каким-то чудом на форуме минта был обнаружен рецепт для исправления этой ситуации, привожу его тут, может кому пригодится тоже (я использую оконный менеджер xfce, поэтому и рецепт соответствующий, можно заменить на любой другой какой вы используете у себя):

echo "env -u SESSION_MANAGER -u DBUS_SESSION_BUS_ADDRESS xfce4-session" > ~/.xsession

При запуске менеджера сессий очищаются 2 переменные окружения, что делает возможность удаленного входа без отключения уже существующих на пк локальных сеансов.


пятница, 11 октября 2019 г.

Как мониторить SMART и выводить результат в Telegram

Решая свою задачу обнаружил интересный пример на Реддите.

SMART Info w/ Telegram Notifications [Linux]

Yesterday I asked how to get warnings of failing drives on Debian 8.8 Today I woke up to some very helpful comments that I'd like to stitch together for all of you to easily enable your server "speaking" capabilities. (Easier to learn it to speak than asking it through the terminal "How you doin?")
  • Installed smartmontools
  • Check all disks are SMART enabled:
    df -h
    sudo smartctl --info /dev/ | grep 'SMART support is:'
  • Create a new telegram bot via the botfather (see https://core.telegram.org/bots#3-how-do-i-create-a-bot). You will need the token of the bot from botfather.
  • I suggest download and installing Postman. A very powerful free API tool. Postman
  • Initiate a chat with your new bot.
  • Open Postman and send a GET to https://api.telegram.org/bot{YOUR_TOKEN}/getUpdates. You will need the chat id called "id": xxxxxx. This ID-number is shown several times in the return JSON file.
  • Open the file /etc/default/smartmontools
  • uncomment the lines
start_smartd=yes smartd_opts="--interval=1800"
  • In the file /etc/smartd.conf use the first example that might be uncommented already and change it to
DEVICESCAN -d removable -n standby -m root -M test -M exec /usr/share/smartmontools/smartd-runner
  • Create a bash file in the folder /etc/smartmontools/run.d called 10telegram-notify and fill in this content (replace token and chat id):
#!/bin/bash -e
chatid="YOUR_CHAT_ID"
error=$(cat $1)
apikey="YOUR_BOT_TOKEN"
curl -G --data-urlencode "chat_id=${chatid}" --data-urlencode "text=${error}" https://api.telegram.org/bot${apikey}/sendMessage
  • Make the file executable: sudo chmod +x /etc/smartmontools/run.d/10telegram-notify
  • Start the daemon sudo smartd. You should be receiving a test message in the chat with your bot. If not, you can investigate the error with sudo cat /var/log/syslog
  • Remove the -M test from your /etc/smartd.conf file, so that the line looks like this now: DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner
  • Finished :)

How to record sound by Linux application

Время от времени на окне на работе поют птички. Подумалось - как бы записать их пение в автоматическом режиме с использованием Linux?

Нашлось несколько вариантов:


Буду тестировать!