Bash examples

Rsync to Android

Connecting Android to your Linux you need to use gvfs. Rsync also wants to set files timestams that is why you need this hack.

 

0. Install gvfs-fuse

For use MTP devices in terminal need to use gvfs-use:

apt install gvfs-use

and reboot.

 

1. Find MTP device in /run/user/1000/gvfs

ls /run/user/1000/gvfs
'mtp:host=Samsung_A7_caf675d6'

Next follow to that folder you need to store your data.

 

Compare Time and Dates in Bash. And the Simplest Alarm on Bash

Using bash it is possible to compare time easily in epoch format. If you need to compare date like 14:23 with 14:17 you need to transform it to seconds since epoch and compare as two integers. Here it is my function in ~/.bashrc and examples

 

Bash: Count Minutes and Seconds since Start of a Process

Starting long process you may want to watch how much time is it going. This helps you to guess how much time remains.

Usually you run some process and then watch on it in another terminal window in a loop `while [ 1 ]`.

For example, need to count minutes since the process start. Algorithm and simple bash script are here.

 

1. Store the start time in seconds in a variable

start=$(date +%s)

This stores start point as POSIX time in seconds like: 1660042758

 

System Monitoring Using Telegram Bot

Having systems that need a monitoring or alert about errors and fails you may use Telegram Bot. Next examples of using Telegram Bot help to watch the status of a long process, also to send lines from log, and even more, it is possible to send printscreens or also convert printscreens to text and then send it to your chat in Telegram.

This way you can monitor any process in your system with smartphone in any place.