Ubuntu – To sudo-tar by Transcend StoreJet’s Backup Button

16.04backup

Condition: bind a function to Transcend StoreJet's Backup button
Differential conditions: no driver for the button in Linux through USB3
Exclude: all graphical backup softwares

The product Transcend StoreJet 25M3 Anti-Shock has a backup button. I would like to that the press of the button starts the function

#!/usr/bin/env bash

# bind this script to the press of the button in the external HDD

# mchid for pkexec
pkexec env DISPLAY=:0 XAUTHORITY=$HOME/.Xauthority \
    tar czf /media/masi/Transcend/backup_home_10.7.2016.tar.gz $HOME/

Pseudocode

  1. ask password for sudo
  2. How to Bind the button to the script?

System: Linux Ubuntu 16.04 64 bit
Linux kernel: 4.4 and 4.6
Linux kernel options: wl
Hardware: Macbook Air 2013-mid, ….
Related thread: Transcent StoreJet auto backup
External HDD: Transcend 1 TB StoreJet 25M3
Bash: 4.3.46(1)-release (x86_64-pc-linux-gnu)

Best Answer

This is actually two questions and you should ask this as two questions instead of one.

With that said, you can use pkexec instead of sudo to get a prompt for a password before executing the script like so:

#!/bin/bash

pkexec env DISPLAY=:0 XAUTHORITY=$HOME/.Xauthority tar czf media/masi/Transcend/backup_home_$(date +%d.%m.%Y | sed 's/\(0\)\(.\)\(\.\)/\2\3/g').tar.gz $HOME/