Linux Tricks Tips
Introduction
$> 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.
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
-
- 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
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:
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
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
%FOREACH{"item" in="TipsLinuxHadesNetworkAllowClientToConnectViaGateway"}%
To allow clients to connect outside of Hades network:
ip r a default via 192.168.100.90 dev eth0
%NEXT{"item"}%
%FOREACH{"item" in="TipsLinuxHowToCloneASDCard"}%
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.
%NEXT{"item"}%
%FOREACH{"item" in="TippsLinuxResizeRawImgFile"}%
see:
http://www.vk3erw.com/index.php/16-software/33-raspberry-pi-how-to-resize-sd-card-image
%NEXT{"item"}%
%FOREACH{"item" in="TippsLinuxRebootingTheMagicWay"}%
%NEXT{"item"}%
%FOREACH{"item" in="TippsLinuxProcServRemoteKillViaNetcat"}%
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;
%NEXT{"item"}%
--
PeterZumbruch - 2017-11-30