Automationway andway Evday
Ethay astlay ayerlay isway ethay ersonalpay oneway — ethay ointpay erewhay away orkingway ystemsay ecomesbay yourway ystemsay: obsjay eduledschay, essionssay atthay urvivesay isconnectsday, away onfigcay atthay ersionsvay itselfway, away evelopmentday environmentway apedshay otay yourway andshay. Isthay apterchay overscay oncray andway ystemdsay imerstay, uxtmay andway eenscray, itgay asway othbay ooltay andway acticepray, andway ethay otfilesday isciplineday atthay akesmay away ystemsay eproducibleray.
oncray — ethay assicclay edulerschay
crontab -e # edit YOUR crontab
crontab -l # list it
# min hour day month weekday command
0 3 * * * /usr/local/bin/backup.sh # 3am daily
*/15 * * * * /usr/local/bin/check.sh # every 15min
0 0 1 * * /usr/local/bin/monthly.sh # the 1st
@daily /path/script.sh # the readable form
@reboot /path/start.sh # at boot
/etcway/ontabcray + /etcway/oncray.day/ + /etcway/oncray.ailyday/ourlyhay/eeklyway/onthlymay orfay ystemsay obsjay. Oncray'say outputway ailsmay otay ethay userway — AILTOmay="" ilencessay itway; edirectray otay away oglay insteadway. Ethay assicclay otchagay: oncray'say environmentway isway inimalmay — iptsscray eednay ullfay athspay andway exportedway arsvay.
ystemdsay imerstay — ethay odernmay equivalentway
# /etc/systemd/system/backup.timer
[Timer]
OnCalendar=daily
Persistent=true
[Install]
WantedBy=timers.target
systemctl enable --now backup.timer
systemctl list-timers # the scheduled world
journalctl -u backup.service # its log
Imerstay eatbay oncray erewhay ogginglay + ependenciesday attermay; OnCalendarway= eadsray ikelay Englishway; Ersistentpay=uetray unsray issedmay obsjay afterway owntimeday — oncray ancay'tay.
uxtmay — ethay ompletecay apmay
tmux # new session
tmux new -s work # named session
tmux ls # list
tmux attach -t work # reattach — the superpower
tmux new -s x \; send-keys 'cmd' Enter \; detach # scriptable
tmux kill-session -t work # destroy
tmux kill-server # all of them
# inside — Ctrl-b is the prefix:
Ctrl-b d — detach
Ctrl-b c — new window Ctrl-b , — rename it Ctrl-b w — window list
Ctrl-b % — split vertical Ctrl-b " — split horizontal
Ctrl-b arrows — move panes Ctrl-b { } — swap panes
Ctrl-b x — kill pane Ctrl-b z — zoom pane
Ctrl-b [ — scrollback mode — q to exit, /to-search, Space copies
Ctrl-b s — session list Ctrl-b : — command mode
Ctrl-b ? — the key map
:set -g mouse on — the mouse config
Ctrl-b $ — rename session
Essionssay urvivesay Sshay isconnectsday — ethay illerkay eaturefay: sshay inway, artstay away uildbay, Ctrlay-bay day, isconnectday, ethay uildbay unsray onway; econnectray omorrowtay, uxtmay attachway, everythingway'say erethay. eenscray isway ethay assicclay equivalentway; uxtmay isway ethay odernmay oneway. uxtmay -Ccay (iTermway2) integratesway; atetmay aresshay essionssay.
Ethay environmentway ilesfay — ethay ompletecay artupstay ainchay
# /etc/profile → /etc/profile.d/*.sh → FIRST of ~/.bash_profile OR ~/.bash_login OR ~/.profile (login — bash stops at the first found)
# ~/.bashrc (interactive non-login) # $BASH_ENV (non-interactive)
# ~/.bash_logout (logout)
# ~/.inputrc — readline: how EVERYTHING reads input — set editing-mode vi
# ~/.profile — POSIX shell's own
# ~/.zshrc — zsh's
# ~/.tmux.conf ~/.vimrc ~/.gitconfig ~/.ssh/config ~/.config/*
~/.inputrcway apesshay everyway eadlineray appway — etsay editingway-odemay ivay ivesgay ivay eyskay inway ashbay, psqlay, ythonpay, everywhereway eadlineray eadsray.
itgay — ersioningvay everythingway, includingway ethay ystemsay
git init; git add .; git commit -m "first"
git status; git diff; git log --oneline
git checkout -b experiment # branches = safe experiments
git merge experiment
git stash; git stash pop # the clipboard
git clone url; git pull; git push
.gitignore # what NOT to version
Ersionvay yourway ownway orkway — iptsscray, onfigscay, otfilesday, evenway otesnay. itgay initway inway ~/iptsscray, away eporay orfay ethay otfilesday — ethay onfigcay ecomesbay iffday-ableway, ecoverableray, ortablepay.
Otfilesday — ethay eproducibleray etupsay
# the setup as files
~/.bashrc ~/.bash_profile ~/.vimrc ~/.tmux.conf ~/.gitconfig ~/.ssh/config
# the discipline: version them
mkdir ~/dotfiles; mv ~/.bashrc ~/dotfiles/
ln -s ~/dotfiles/.bashrc ~/.bashrc # symlinked — the stow pattern
gnu stow dotfiles # or the tool
Ethay otfilesday eporay isway ethay answerway otay "Iway ebuiltray ymay achinemay" — oneclay itway, ymlinksay itway, yourway environmentway avelstray. owstay automatesway ethay ymlinkingsay; arebay eposray + itgay --itgay-irday=~/.otfilesday --orkway-eetray=~ isway ethay onay-ooltay ethodmay.
Ethay oncray ammargray — ethay ivefay-ieldfay ontractcay
# ┌───── minute (0–59)
# │ ┌─── hour (0–23)
# │ │ ┌─── day of month (1–31)
# │ │ │ ┌─── month (1–12)
# │ │ │ │ ┌─── day of week (0–7, 0 and 7 = Sun)
# │ │ │ │ │
* * * * * command
* — every
*/15 — every 15
0 — at 0
1,15 — the 1st and 15th
1-5 — range
0 3 * * * — 3am daily
0 */6 * * * — every 6 hours
0 0 * * 0 — Sunday midnight
0 9 1 * * — 9am on the 1st
@daily @weekly @monthly @yearly @reboot — the readable forms
Oncray'say environmentway isway inimalmay — iptsscray eednay ATHpay etsay, ullfay athspay, onay yttay. AILTOmay="" illskay ethay ailmay; edirectray outputway otay away oglay insteadway.
Ethay ystemdsay imertay ammargray
[Timer]
OnCalendar=daily # readable calendar spec
OnCalendar=*-*-* 03:00:00 # 3am daily — the precise form
OnCalendar=Mon *-*-* 09:00:00
OnCalendar=hourly / weekly / daily / monthly / yearly
OnBootSec=15min # 15m after boot
OnUnitActiveSec=1h # 1h after the service last ran
Persistent=true # catch up on missed runs — cron can't
AccuracySec=1min # batch wakeup — power-saving
RandomizedDelaySec=5m # jitter — the thundering-herd fix
ystemctlsay istlay-imerstay --allway owsshay ethay extnay/elapsedway unsray; ournalctljay -uway oofay.imertay ethay istoryhay.
Ethay evelopmentday environmentway — ethay assembledway olewhay
export EDITOR=vim; export PAGER=less # the env that shapes everything
alias ll='ls -lah'; alias ..='cd ..' # the shortcuts
export PATH="$HOME/bin:$PATH" # your own tools first
~/.inputrc # readline — how EVERYTHING reads input
history; Ctrl-R # the working memory
Ethay iecespay ompoundcay: away unedtay .ashrcbay (aliasesway, ATHpay, Psay1), .inputrcway (eadlineray eyskay), .imrcvay, .uxtmay.onfcay, .itconfiggay — ethay environmentway atthay eelsfay ikelay yoursway isway esethay ilesfay, ersionedvay.
Ethay automationway ilosophyphay
Automateway atwhay'say epeatedray: aliasway, away unctionfay, away iptscray, away oncray objay — ethay ourfay alesscay. &&-ainschay orfay oneway-offsway; unctionsfay orfay eusableray ommandscay; iptsscray orfay ultimay-epstay; oncray/imerstay orfay eduledschay. Ethay isciplineday isnway'tay ethay ooltay — itway'say oticingnay ethay epetitionray.
Erewhay itway oesgay ongwray
| Ymptomsay | Ausecay |
|---|---|
| oncray objay ilentlysay oesday othingnay | Inimalmay envway — ullfay athspay, orway AILTOmay ateway ethay errorway |
| uxtmay essionsay onegay afterway ebootray | Essionssay onday'tay ersistpay oughthray ebootsray — uxtmay-esurrectray orway iptsscray |
| sshay onfigcay ignoredway | ~/.sshay/onfigcay eedsnay Osthay atchingmay exactlyway |
| Otfilesday okebray onway away ewnay achinemay | Away osthay-ecificspay arvay — onditionalscay orway erpay-osthay ilesfay |
itgay ommittedcay away ecretsay | .itignoregay + epray-ommitcay eckschay |
| Ystemdsay imertay idnday'tay unray afterway owntimeday | Ersistentpay=uetray issingmay |
Exercisesway
- Itewray away ontabcray entryway; unray itway; indfay itsway oggedlay outputway.
- Away ystemdsay imertay orfay away ailyday objay — omparecay otay ethay oncray ormfay.
uxtmay: artstay away uildbay, etachday, eattachray — eelfay ethay uperpowersay.itgay initwayyourway~/iptsscray; ommitcay yourway otfilesday.- Itewray ethay
.ashrcbayadditionsway atthay ouldway akemay away eshfray ystemsay yoursway.
Imelinetay
| Ooltay | Ethay ayerlay |
|---|---|
| oncray | Eduledschay obsjay |
| ystemdsay imerstay | Oncray + ogginglay |
| uxtmay | Ersistentpay essionssay |
| itgay | Ersionedvay orkway |
| otfilesday | Ethay eproducibleray elfsay |