From personal use - Windows - Scripting - Bash - Awk - Distributions - Debian - Configuration management software - To explore - See also

This page is a quick references for common problems I had and the quick fix to move on. There is no complex script here, check instead shell_scripts for an attempt at structuring the small scripts I use often and thus try to maintain.

From personal use

  • inotifywait from the inotify-tools package
    • inotifywait -m /data/ -e modify | while read path action file; do date +%s >> /tmp/modified; done
      • adding -e create can result in 2 events being fired, 1 for file creation then another for modification
        • prefer instead -e close_write
      • filename accessible as $file
    • works through Docker volumes
  • multiple ssh servers on 1 IP while keep strict checking
  • vinagre as VNC client
    • vinagre IP:port
      • if password saved and keyring working goes straight to the remote computer
    • used tightvnc server side (~5min setup making sure the computer is in the DMZ)
  • Nautilus mount points on Ubuntu 15+
    • /run/user/...UID.../gvfs/...
    • useful to run scripts
  • rsync
    • -i to only shown uploaded files and why
  • copy content from terminal
    • echo content | xclip -selection c
  • toggle touchpad
    • test 0 -eq `synclient | grep TouchpadOff | sed "s/.*\(.\)$/\1/"` && synclient TouchPadOff=1 || synclient TouchPadOff=0

^ : Control key
meta : Alt key

Windows cmd.exe shell

  • cygwin/mingw
    • notes on path (e.g. interpreter like ruby, no probleme with java paths, ...)
    • MingW system variables are available as $UP not%UP%
  • sc delete servicename : remove the service
    • still require to first stop it then delete it from the registry
  • ifconfig /flushdns : force to discard the current DNS cache (useful if hosts configuration has been updated)
  • attrib changes attributes of files and directories
  • devcon to unmount devices including USB keys
    • devcon remove @usb\vid*
  • Windows Server 2003 Resource Kit Tools including timeit
  • fsutil volume diskfree C: : free space (in bytes) in the C: hard drive
  • shutdown -r -t 0 : reboot now
    • shutdown -a : abort shutdown
  • cd /D x:\path\
    • actually switches to the other directory on the other drive
  • packing and sending daily backup
    • set dt=%date:~10,4%%date:~4,2%%date:~7,2%
    • 7z a internalwiki_%dt%.tar wiki
    • 7z a internalwiki_%dt%.tar.bz2 internalwiki_%dt%.tar
    • del internalwiki_%dt%.tar
    • pscp internalwiki_%dt%.tar.bz2 user@server.tld:/home/user/backups_path/
  • tasklist : list the active processes
    • WMIC PROCESS get Caption,Commandline,Processid
  • doskey /history > mycommands.txt : save the commands you typed in the mycommands.txt file
  • path %path%;c:\myother\bin\path\; : appends the directory to the current path
    • note that this is not a permanent change
  • 7z : use 7zip command-line interface
    • 7z a internalwiki.tar wiki then 7z a internalwiki.tar.bz2 internalwiki.tar
  • Stupid Command Prompt Tricks by Jeff Atwood, Coding Horror 2005
  • Windows : Command Processor, PC Tools
  • PowerShell by Microsoft
    • recommended by Jonathan

PuTTY suite

  • pscp
    • does require the -agent option to check for Pageant running instances
    • and obviously a working key pair
    • yet... it sometimes seem to work without!?
  • pageant
  • PuTTY Tray improved version of PuTTY (Win32). It features some cosmetic changes, and a number of addons to make it more useful and much more fun to use.
  • KiTTY as recommended in #tmux on freenode

Scripting

Warning, this section is really shell specific (i.e. bash != zsh ...)

  • sed
    • expression1\|expression2 = Matches expression1 or expression (esp with GNU sed)
    • see Vi and PmWiki for other regular expressions
    • crontab -l | sed "/^SSH_AUTH_SOCK/s,[^=]*$,$SSH_AUTH_SOCK," | crontab
      • no need for `` or $() since it is a global variable
      • delimiter changed to take into account the slashes in the path
  • note that sed does allow access to environment variables and even to execute command but the ouput should not in include the delimiter
    • e.g. x=`whoami`; echo "fff" | sed "s/ff/$x /" will work
      • but fail if there is / in the username
        • if it is the case and you can predict with certainty the character then change the delimiter e.g. x=`whoami`; echo "fff" | sed "s|ff|$x |"

Check my ~/backups/*.sh and ~/bin/*.sh for examples

Bash

  • http://mywiki.wooledge.org/RegularExpression from Bash guide
    • see also the associated #bash channel on freenode
  • history especially as with screen ~/.bash_history does no cover all the commands
    • practical also to get the lat commands via e.g. tail and to output them into a future script
      • history | tail -30 > my_new_bash_script
  • Making sure it is being executed in the right environment
    • #!/bin/bash
  • Link to the motivation and the context
    • # http://related/wiki/URL
  • Testing for explicit help or improper number of argument
    • EXP_ARGS=1
      if [ "$1" = "--help" -o "$1" = "-h" -o $# -lt $EXP_ARGS ]
      then
        echo "Check against dead link for PmWiki"
        echo "usage: $0 [PmWiki_path]"
        echo "if the second parameter is omitted path is assumed to be ..."
        exit
      fi
      WORD=$1
      DEST=$2
      
    • should be generalized to most of ~/bin scripts following Path:/pub/videolectures.sh.txt
  • Handling omitted arguments
    • # if $2 is empty, use the last part of the URI
      if [ $# -lt 2 ]
      then
        DEST=.
      fi
      
  • date -d @1234909950 to convert unixtime time stamp to the default format
  • for loop
    • for X in $(ls $1/path/* | grep -v ExcludeThis | grep -v Site | sed "s/.*wiki\.d\///")
      do
       this $1/path/$PAGE > $1/other_path/$PAGE.data;
       that $1/other_path/$PAGE.data;
      done;
      
  • LANG=en_EN.utf-8 (required in the terminal and the application too)
  • $@ to handle every arguments passed to the script
  • PS1="[\u@\w]$ " set permanently in in ~/.bashrc
  • seq -w -s" " 1 12 returns 01 02 03 04 05 06 07 08 09 10 11 12
  • $((do some math))
  • echo $(( $(cat file | sed "s/.*\d//" | wc -l) * 1024))

See also env, export, printenv, etc...

Awk

  • awk '{print $2}'
  • grep action=edit page_generated.txt | awk '{ SUM += $2} END {print SUM}'

Distributions

Debian

  • systemctl suspend to sleep
    • useful to stop after a long task with a boot proper, e.g sudo dd if=/dev/sdb of=./pimetaapnaf.img bs=32M && sudo systemctl suspend
  • man:checkinstall
  • Debian Administration System Administration Tips and Resources
  • http://packages.qa.debian.org/w/win32-loader.html
    • parameters to load an ISO file
  • Debian Backports
    • recompiled packages from testing (mostly) and unstable (in a few cases only, e.g. security updates), so they will run without new libraries (wherever it is possible) on a stable Debian distribution.
  • installing from source
    • apt-get update
    • apt-get install build-essential
    • apt-get -b source package
    • dpkg -i package_versionnumber_arch.deb
    • updatedb
    • locate package | more
  • cat /etc/debian_version
    • or lsb_release -a
  • dpkg --search /file/whose/package/is/unknown
  • dpkg -L packagename to list the files from a specified package

Configuration management software

See also the WebWorkersCampParis talk and the "infrastructure as code" paradigm presented during Automated Infrastructure is on the Menu with Chef, O'Reilly Webcast July 2010

  • Nimbus open source toolkit that allows you to turn your cluster into an Infrastructure-as-a-Service (IaaS) cloud.

To explore

See also


Note

My notes on Tools gather what I know or want to know. Consequently they are not and will never be complete references. For this, official manuals and online communities provide much better answers.