Epics@GSI Webhome

Linux Tricks Tips

Introduction

serial device settings - switch off every possible hidden manipulation feature

$> stty -F /dev/ttySx -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 19200

    • Output settings:
      -opost
      do not post-process output
      -onlcr
      do not translate newline to carriage return-newline
    • Local settings:
      -isig
      do not enable interrupt, quit, and suspend special characters
      -icanon
      do not enable erase, kill, werase, and rprnt special characters
      -iexten
      do not enable non-POSIX special characters
      -echo
      do not echo input characters
      -echoe
      do not echo erase characters as backspace-space-backspace
      -echok
      do not echo a newline after a kill character
      -echoctl
      do not echo control characters in hat notation ('^c')
      -echoke
      kill all line by obeying the echoctl and echok setting
      19200
      sets the speed to 19200 Bit/s

    Summarizing the settings prevent any additional manipulation of input or output.

-- PeterZumbruch - 2020-11-09

udev/udevadm allows to automatically assign (fixed) symbolic links for USB devices connected to the system pointing the current /dev entry point.

Prerequisites
you have to have admin rights.

How to
  • edit/create /etc/udev/rules.d/99-serial-permissions.rules
    • add the follwing line for general includes
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", SYMLINK+="$env{ID_SERIAL}", GROUP="users", MODE="0666"
      creates for every connected device of vendor id 0403 a symbolic link /dev/ to the connected device
    • for special devices those lines can be added in addition
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A100dQ2B", SYMLINK+="hadcon2", GROUP="users", MODE="0666"
      SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A600801P", SYMLINK+="olimex", GROUP="users", MODE="0666"

    • for special devices (e.g. HadCon2) those lines can be added in addition
      • SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A100*", RUN+="/usr/bin/stty -F /dev/$kernel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 115200 "
      • SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", ENV{ID_SERIAL}=="FTDI_FT232R_USB_UART_A801*", RUN+="/usr/bin/stty -F /dev/$kernel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke 115200 "
  • to find out the IDs of connected systems
    udevadm info --export-db| grep FTDI| grep ID_SERIAL

  • Finally reload rules and trigger a reconnect:
    udevadm control --reload-rules
    udevadm trigger

Links
"Writing udev rules"
http://reactivated.net/writing_udev_rules.html
udev
https://wiki.ubuntuusers.de/udev/
"Tutorial on how to write basic udev rules in Linux"
https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux

-- PeterZumbruch - 2019-03-22

SSH config: Host Specific Identity

Using ssh config files in ~/.ssh/config allows to specify per host / host alias different user/identity to connect with and more necessary options.

Using the features of the config file of ssh in ~/.ssh one can specify host specific ssh options, including varying identities and users.

from: http://www.gelato.unsw.edu.au/archives/git/0611/31044.html

Example:
  • connecting to a specific host using a different identity file and user
    $> cat ~/.ssh/config
       Host private.host.com
          User myname
          Hostname host.com
          IdentityFile ~/.ssh/private-identity
       Host public.host.com
          User anotherName
          Hostname host.com
          IdentityFile ~/.ssh/public-identity
       Host git.host.com
          User git
          Hostname host.com
          IdentityFile ~/.ssh/git-identity
         
  • allows to replace:
    • ssh host.com -l myname -i ~/.ssh/private-identity
      by
      ssh host.com
    • commands which internally use ssh but do not allow to pass ssh options, e.g. git
      git clone git.host.com

-- PeterZumbruch - 2020-11-09

Linux: dhclient - dynamic hostname

Using dhclient exit hooks scripts allows to set e.g. the hostname dynamically

Based on the articles: and its own origin

dhclient and its scripting capabilities on enter and exit hooks allows to react on dynamic network environments.

Provided you have root privileges this can be achieved by creating a script file hostname created in /etc/dhcp/dhclient-exit-hooks.d/ (on Debian), which is sourced by dhclient after having updated/received its DHCP informations.

#!/bin/sh
   # Filename:     /etc/dhcp/dhclient-exit-hooks.d/hostname
   # Purpose:      Used by dhclient-script to set the hostname of the system
   #               to match the DNS information for the host as provided by
   #               DHCP.
   #
      
   # Do not update hostname for virtual machine IP assignments
   if [ "$interface" != "eth0" ] && [ "$interface" != "eth1" ] && [ "$interface" != "wlan0" ]
   then
           return
   fi
      
   if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
   then
      return
   fi
   
   echo dhclient-exit-hooks.d/hostname: Dynamic IP address = $new_ip_address
   hostname=$(a=$(host $new_ip_address) || { false; } && { echo -n $a | cut -d ' ' -f 5 | cut -d "." -f 1; true; }) || unset hostname &&
   echo ${hostname?} > /etc/hostname &&
   hostname $hostname &&
   export HOSTNAME=$hostname &&
   echo dhclient-exit-hooks.d/hostname: Dynamic Hostname = $hostname

Applying those code lines: %FOREACH{"file" in="/etc/dhcp/dhclient-exit-hooks.d/hostname"}%
sudo curl -s https://wiki.gsi.de/pub/Epics/TipsLinuxDhclientDynamicHostname/_etc_dhcp_dhclient-exit-hooks.d_hostname -o $file && 
  sudo dos2unix $file && 
  sudo chmod a+r $file
%NEXT{"file"}%

Local testing at the prompt:
dhclient

-- PeterZumbruch - 2018-11-30

Linux: dhclient - dynamic mount point

Using dhclient exit hooks scripts allows to set a mount point depending on the network environment, in this example for the HADES setup

Based on the articles: and its own origin

dhclient and its scripting capabilities on enter and exit hooks allows to react on dynamic network environments.

Provided you have root privileges this can be achieved by creating a script file mount_var_diskless created in /etc/dhcp/dhclient-exit-hooks.d/ (on Debian), which is sourced by dhclient after having updated/received its DHCP informations.

#!/bin/sh
    # Filename:     /etc/dhcp/dhclient-exit-hooks.d/mount_var_diskless
    # Purpose:      Used by dhclient-script to set mount HADES's var/diskless filesystem 
    #               from either the local net (preferred) or the GSI network
    #
    
    # Do not update hostname for virtual machine IP assignments
    if [ "$interface" != "eth0" ] && [ "$interface" != "eth1" ] && [ "$interface" != "wlan0" ]
    then
        return
    fi
    
    if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" != REBIND ] && [ "$reason" != REBOOT ]
    then
            return
    fi
    
    var_diskless_hades=192.168.100.50
    var_diskless_gsi=140.181.75.158 
    var_diskless_path=/var/diskless/dreamplug
    var_diskless_mount=/var/diskless/dreamplug
    
    echo dhclient-exit-hooks.d/mount_var_diskless: new domain-name-servers: $new_domain_name_servers 
    
    echo "$new_domain_name_servers" | grep -q $var_diskless_hades && var_diskless_addr=$var_diskless_hades || var_diskless_addr=$var_diskless_gsi
    
    #clean up, but only different mounts
    grep -v "$var_diskless_addr:$var_diskless_path" /etc/mtab | grep -q "$var_diskless_mount" && umount $var_diskless_mount 
    
    #mount
    [ -d "$var_diskless_mount" ] || mkdir -p $var_diskless_mount
    grep "$var_diskless_addr:$var_diskless_path" /etc/mtab | grep -q "$var_diskless_mount" || mount $var_diskless_addr:$var_diskless_path $var_diskless_mount
    
    echo dhclient-exit-hooks.d/mount_var_diskless: mounted $var_diskless_addr:$var_diskless_path
    
    unset var_diskless_hades 
    unset var_diskless_gsi 
    unset var_diskless_path 
    unset var_diskless_mount
    
Finally make sure the file is readable:
chmod a+r /etc/dhcp/dhclient-exit-hooks.d/mount_var_diskless

Local testing at the prompt:
dhclient -v

-- PeterZumbruch - 2020-11-09

%FOREACH{"item" in="TipsLinuxHadesNetworkAllowClientToConnectViaGateway"}%

Linux: Hades Network - Allow Client To Connect Via Gateway

To allow clients to connect outside of Hades network:
  • with root privileges
ip r a default via 192.168.100.90 dev eth0

-- WikiGuest - 1970-01-01

%NEXT{"item"}%

%FOREACH{"item" in="TipsLinuxHowToCloneASDCard"}%

Linux: How To Clone A SD Card

Following the help of page https://startingelectronics.org/articles/raspberry-PI/ten-things-raspberry-PI chapter 10.

This video View on YouTube → shows how to clone an SD card in Linux using the dd command line application.

The command for copying an SD card to an image file on your computer is:
sudo dd if=/dev/mmcblk0 of=~/raspi.img
The command for copying an SD card image to a new SD card is:
sudo dd if=~/raspi.img of=/dev/mmcblk0
Where:
  • ~/raspi.img is the location and file name of the image file.
  • /dev/mmcblk0 is the SD card device on the Linux system.

-- WikiGuest - 1970-01-01

%NEXT{"item"}%

%FOREACH{"item" in="TippsLinuxResizeRawImgFile"}%

Linux: Resize Raw Img File

see: http://www.vk3erw.com/index.php/16-software/33-raspberry-pi-how-to-resize-sd-card-image

-- WikiGuest - 1970-01-01

%NEXT{"item"}%

%FOREACH{"item" in="TippsLinuxRebootingTheMagicWay"}%

/sbin/reboot: Input/output error

LinuxJournal-ReBootingTheMagicWay.png

-- WikiGuest - 1970-01-01

%NEXT{"item"}%

%FOREACH{"item" in="TippsLinuxProcServRemoteKillViaNetcat"}%

ProcServ: Remote Kill Via netcat

ProcServ usually needs a login to its port to execute a "CTRL+X" sequence to kill/restart the current child process. Thanks to this cmdline it is also able without. Thanks to J.Michel / M.Traxler, afaik.

Solution

Assuming that procServ is running its telnet session on port 12345 on localhost
echo -en "\x18" | netcat -w1 localhost 12345;

-- WikiGuest - 1970-01-01

%NEXT{"item"}%


-- PeterZumbruch - 2017-11-30
-- PeterZumbruch - 2018-11-30
Topic revision: r9 - 2018-11-30, PeterZumbruch - This page was cached on 2024-12-19 - 19:30.

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding GSI Wiki? Send feedback | Legal notice | Privacy Policy (german)