Scripting with Bash Compact Course @ MPE Moritz August March 14 - - - PowerPoint PPT Presentation

scripting with bash
SMART_READER_LITE
LIVE PREVIEW

Scripting with Bash Compact Course @ MPE Moritz August March 14 - - - PowerPoint PPT Presentation

Scripting with Bash Compact Course @ MPE Moritz August March 14 - 16, 2017 Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 1 Part IV Working Remotely And More Moritz August: Scripting with Bash Compact Course


slide-1
SLIDE 1

Scripting with Bash

Compact Course @ MPE

Moritz August

March 14 - 16, 2017

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 1

slide-2
SLIDE 2

Part IV Working Remotely And More

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 2

slide-3
SLIDE 3

Working remotely - ssh, scp and tmux

ping

  • ping hostname
  • Useful to find out whether some machine is down or has no

connection.

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 3

slide-4
SLIDE 4

Working remotely - ssh, scp and tmux

ping

  • ping hostname
  • Useful to find out whether some machine is down or has no

connection. ssh and scp - security by encryption

  • Developed 1995 to allow secure connections between computers
  • ssh username@computername log in onto computername as

username

  • scp -r * username@computername:<path_rel_to_home>
  • scp *.txt username@computername:/<absolute_path>
  • scp "username@computername:path/*.*"./ – copy all remote files

in folder path to current directory

  • Quotes necessary for remote wildcards

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 3

slide-5
SLIDE 5

Working remotely - ssh, scp and tmux

Tunneling connections

gname @gate local rname @remote XY 22 XX ssh ssh 22

  • You can ssh from local machine to gate
  • You can (e.g.) ssh from gate to remote
  • You cannot directly access remote
  • Then use ssh for tunneling the connection

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 4

slide-6
SLIDE 6

Working remotely - ssh, scp and tmux

Tunneling connections

gname @gate rname @remote gname @gate local rname @remote XY 22 XX ssh ssh 22 local XX

8888

ssh 22 XY 22

  • You can ssh from local machine to gate
  • You can (e.g.) ssh from gate to remote
  • You cannot directly access remote
  • Then use ssh for tunneling the connection

ssh -L 8888: < remote >:22 <gname >@<gate > # then in other terminal scp -P 8888 file.txt <rname >@localhost:some/dir ssh -p 8888 <rname >@localhost

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 4

slide-7
SLIDE 7

Working remotely - tmux

  • during a typical session, many terminals are used
  • if working remote, this means opening many ssh connections
  • for each login/logout, everything has to be closed/opened again
  • tmux solves all these problems by creating virtual terminals
  • tmux commands can be accessed by Ctrl+b
  • Ctrl+b, % creates a new pane
  • Ctrl+b, " splits pane into two panes
  • Ctrl+b, x kills pane
  • Ctrl+b, c creates new window
  • Ctrl+b, & kill window
  • Ctrl+b, <Arrow> switch pane
  • Ctrl+b, <Number> switch window
  • Ctrl+b, d detach from tmux
  • tmux a attach to tmux

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 5

slide-8
SLIDE 8

Some more commands you should know

basename "this/is/the/path/to/a.file" dirname "this/is/the/path/to/a.file" time sleep 3 time for i in `seq 100000 `; do a=$[3*$i]; done users groups du -sh df -h ln -s <file > <link >

Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 6