There’s a reason root’s ‘#’ prompt gets interpreted as a comment.
‘>database.zone’ now means database.zone is a zero byte file. Whoops.
">" replaces file contents. ">>" appends to the existing file.
You will screw this up precisely once in your career.
VMs that live-migrate are awesome until the two redundant things migrate their way onto the same physical host.
Which then suffers a hardware fault.
Systems should be cattle not pets, but your laptop is going to one day go to live at a farm upstate and have its ashes in a commemorative urn.
alias serial_9600_8bit='screen /dev/ttyUSB0 9600,cs8' is a line in my shell config. I haven't used it in eight years but when I need it I'm going to REALLY need it, so there it stays.
Install 'sl' on your laptop to teach you to type 'ls' more accurately.
Install 'sl' into production to teach you why it's important to have friends at work.
You want the shell environment on production servers to be as user-hostile as possible to discourage people from spending time there. I like the korn shell for this.
Some people view their public SSH keys as secret. Those people should avoid looking at github.com / THEIR_USERNAME.keys if they'd like to remain happy.
Every time you run a recursive rm, replace the "rm -r" with "ls" for the first attempt.
You will skip this step. And you will regret it.
In shell scripting, use 'echo' in place of 'ls'. They'll work the same way except in a couple of edge cases that will destroy the goddamned moon.
There is always a desktop under someone's desk, a VM in some unrelated cloud provider, or (nowadays) a raspberry pi somewhere that keeps an eye on the site.
If you don't have one, fix that.
Once you follow this advice, it will be followed shortly thereafter by adding a -u to it.
(-e is stop on error, -u is stop on unset variable)
If a log is filling up your disk, rm'ing the log file won't solve it. The file handle is still open; now you've got to kill -HUP the logging daemon to get it to let go.
'> logfile' avoids this step by truncating.
If running a command and piping the output somewhere still displays output, you're seeing the difference between STDOUT and STDERR. `2 > &1` is a unifying idiom that will restore balance to your universe.
The real value proposition of cloud computing that your boss is sworn to never reveal to you is that it keeps you from physically touching the computers and breaking them.
It's more expensive because it's worth it.
"load-bearing cron jobs running in the sysadmin's account" is the kind of problem you only discover after something important fails to happen.
There are at least three places to stash a cron job on a system. When the other sysadmin is busy patting themselves on the back for finding your clever hack they'll completely forget that 'at' jobs live somewhere else.
'rm -rf /' now requires a '--no-preserve-root' flag in theory, but in practice I've never been brave enough to test it.
In theory there's no difference between theory and practice, but in practice there is.
That difference is called systems administration.
"I don't do sysadmin work, I'm a SRE / DevOp" is what the sysadmin in denial says.
If someone offers me 40% more money to pronounce AMI with two syllables, I'd do that too. Don't leave money on the table for dumb reasons.
A simple way to show disk usage items by size is 'du -k | sort -n | perl -ne 'if ( /^(\d+)\s+(.*$)/){$l=log($1+.1);$m=int($l/log(1024)); printf ("%6.1f\t%s\t%25s | %s\n",($1/(2**(10*$m))),(("K","M","G","T","P")[$m]),"*"x(1.5*$l),$2);}' '
If you accidentally type a password into the shell, it will end up in your shell history. Hope isn't lost!
`kill -9 $$` kills your current logged in process, and dead shells write no logs.
It's best to use $() instead of backticks in shell scripts just to stop the "well, actually" crowd from bothering you.
No matter what system you use to manage your workstation, it will not keep up with what you actually do, and reinstallation will require a bunch of manual work.
`visudo` always beats editing /etc/sudoers manually.
But you're still going to want to have a second shell opened as root beforehand to avoid tears before bedtime.
`netstat -antp |grep LISTEN` shows you what's listening to TCP ports. the "p" doesn't work on Mac, and it's part of net-tools and deprecated on modern Linux, but "ss -lt" lacks the same flair.
There’s systemd, upstart, and a bunch of actually good init systems, but some jackwagon is always going to try to ice skate uphill by parking a command in a tmux or screen session.
When you’re done configuring a box, reboot it to make sure everything starts properly on restart. Otherwise you won’t really be done until after the 3am power outage in eight months.
If your boss tells you your shell scripts need a web interface, very careful phrasing on your part means that shellinabox meets their acceptance criteria. github.com/shellinabox/sh…
Reduce the TTLs on your DNS records a few days before the change or risk annoyed users.
Pointing out that “users are complaining, what’s the story with our monitoring system?” answers its own question must be done delicately.
Draconian policies such as “all production changes require VP approval” can be overturned within hours by following them to the letter.
Draconian policies such as “all production changes require VP approval” can be overturned within hours by following them to the bathroom.
Bad flags to destructive commands, typos in shell paths, and file shares mounted on a system have a convergence point where it's best to begin cleaning out your desk to beat the rush.
`if [ -e FOO]` as a test condition works in part because a command on the system is, and I swear I'm not making this up, `/bin/[`. Develop a stress release before the madness gazes into you.
You will eventually try something one step too cute and somehow manage to delete /dev/null itself.
Pause. Take a deep breath. Revel in the feeling that you've just stormed the gates of hell and killed the devil, then `mknod`.
If you’re coming from Linux, ‘killall’ absolutely doesn’t do what you think it does on Solaris.
You only need to ‘sudo’ to gain privileged access from your usual account if your usual account isn’t root.
You’ll get made fun of for using “cp FILE FILE.bak” as a quick fix backup before testing something, but you might get fired for not backing it up at all. Choose wisely.