Shell

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
^ : Control key
meta : Alt key
~/.ssh/config- in particular for tools using ssh e.g. rdiff-backup or rsync
- http://nerderati.com/2011/03/simplify-your-life-with-an-ssh-config-file/
- Security
- man:cron-apt
- Wikipedia:Sandbox computer security
- see also Security
- to explore
- cdrecord/dvd+rw-format/dvd+rw-mediainfo/mkisofs
- man:xargs e.g. used to handle list of URLs with the rtmpdump script
- backup with relative path and checksum
- DATE=$(date +%F-%HH%M) && tar -C /home/user/path/data/ -cvf ~/place/to/share/backup.${DATE}.tar . && md5sum ~/place/to/share/backup.${DATE}.tar > ~/place/to/share/backup.${DATE}.tar.md5
- this should be put within a script and in crontab
reset: reset the display of the current terminal, useful when you receive data that mess up the display- command-line calculations using bc by Rob Newcater, Basically Tech 2006
- using SSH for tunneling
- man:ssh and man:sshd
- see Censorship#DIY to tunnel your way out (get)
-Ron ssh andGatewayPorts yeson sshd to tunnel your way in (share)- Breaking Firewalls with OpenSSH and PuTTY Mike Chirico
ssh me@server.tld -R binding_address.tld:remoteport:127.0.0.1:443 -N- ideally you would share an encrypted protocol else anybody monitoring the client to your shared service will be able to record the content
- consider Lighttpd/Apache mod_proxy or CGI to convert the specific port to a proper URL
- PATH=$PATH:~/bin/ && export PATH
- most terminals and some apps
- ^T : transpose_characters
- note that those text edits are coherent with irssi (cf Irssi)
- ^K : erase_to_end_of_line
- meta-b : backward_word
- meta-f : forward_word
- meta-d : delete_next_word
- meta-Delete : delete_previous_word
- ^R : history search
- ^T : transpose_characters
- man : help for most available commands
- apropos : find the command that does what you want to do
- locate : find files listed thanks to updatedb
- cd - : go back to the last changed directory
- env : ...
- encapsulate through pipes (thanks to sed)
- grep term ~/file | sed "s/$/<br \/>/" | sed "$ s/^/<html>/" | tac | sed "$ s/$/<\/html>/" > ~/web/mypaths/myfile.html
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 deleteservicename : 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)attribchanges 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 driveshutdown -r -t 0: reboot nowshutdown -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.txtfile - 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 wikithen7z 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
-agentoption to check for Pageant running instances - and obviously a working key pair
- yet... it sometimes seem to work without!?
- does require the
- pageant
- load multiple keys http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter9.html#pageant-cmdline-loadkey
- note that starting multiple pageant results as only the first launched instance being available
- 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
- no need for
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
historyespecially as with screen~/.bash_historydoes no cover all the commands- practical also to get the lat commands via e.g.
tailand to output them into a future scripthistory | tail -30 > my_new_bash_script
- practical also to get the lat commands via e.g.
- 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
~/binscripts 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 @1234909950to 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
- 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
- or
dpkg --search /file/whose/package/is/unknowndpkg -L packagenameto list the files from a specified package
Configuration management software
- Wikipedia:Comparison of open source configuration management software
- Chef systems integration framework, built to bring the benefits of configuration management to your entire infrastructure.
- Cfengine The original Open Source desired-state technology for server configuration management
- Puppet open source framework designed to efficiently manage data center infrastructure.
- AutomateIt open source tool for automating the setup and maintenance of servers, applications and their dependencies.
- Automating Linux and Unix System Administration by Kirk Bauer, Nathan Campi, Apress 2008
- including Allmyapps App Store to find and install the applications
- supporting as of April 2010 Microsoft Windows and Ubuntu
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
- Using your GPG/PGP public key to authorize your ssh connection Marc's Blog 2007
- urlpicker for urxvt
- urlview URL extractor/launcher
- http://kkovacs.eu/cool-but-obscure-unix-tools
See also
- my related tools pages
- Screen
- Vi
- and the related Unix shell vi mode
- shell_sink web accessible version of your bash history, you can search, annotate and tag it.
- commandlinefu.com the place to record those command-line gems that you return to again and again.
- Blinkenshell.org
- Embedding shell clients
- Stow GNU Project
- program for managing the installation of software packages, keeping them separate (/usr/local/stow/emacs vs. /usr/local/stow/perl, for example) while making them appear to be installed in the same place (/usr/local).
- Advanced Bash-Scripting Guide An in-depth exploration of the art of shell scripting by Mendel Cooper
- Linux-libre project removing software that is included without source code, with obfuscated or obscured source code, under non-Free Software licenses, that do not permit you to change the software so that it does what you wish, and that induces or requires you to install additional pieces of non-Free Software.
- Shell Commander PHP script, that allows remote execution of shell commands (like SSH client) through a web browser.
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.
CONTENT
CONTACT
UPDATES
LAST TWEET
RSS for this page only


