The reflex when /etc says no is to put sudo in front. From a script:
$ sudo echo "maxconn=200" > /etc/demo.conf
pd.sh: line 2: /etc/demo.conf: Permission denied
exit=1
$ echo "maxconn=200" | sudo -n tee /etc/demo.conf
sudo: a password is required
ex...
Five lines whose only job is to refuse a deploy when the token is missing. Run with the token unset:
$ cat deploy-guard.sh
!/bin/bash
if -n $DEPLOYTOKEN ; then
echo "token present, deploying"
else
echo "no token, refusing" >&2; exit 1
fi
$ env ...
rm -rf "$TARGET/" looks correct. The quotes are right and the glob sits outside them, where it has to. I put it in a two-line script in a scratch directory and asked what happens when TARGET is empty, with echo in front so rm never ran: the command l...
A four-line cleanup script, cd /srv/drop, rm .log, echo "cleanup done", run on a scratch tmpfs. At 80,290 files it emptied the directory. At 80,291:
$ /srv/cleanup.sh
/srv/cleanup.sh: line 4: /usr/bin/rm: Argument list too long
cleanup done
exit=0
$...
Two rsync commands one character apart both exit 0 and put the same file in different places. I ran them side by side in a scratch directory, rsync 3.5.0, with one file at projects/app/main.sh:
$ rsync -a projects backup-a/
$ find backup-a -type f
b...
On August 6 my laptop booted to a blank terminal. lightdm has Restart=always, and systemctl status said active running. Xorg had entered the NVIDIA init about 140 ms before the device nodes existed and hung there for fourteen hours: state S, 20 ms of...
My dev server came up on 3001 for months because something had 3000. As a normal user, ss -ltnp 'sport = :3000' showed two rows, 0.0.0.0:3000 and :::3000, with nothing under Process. I had seen output like that before and moved on.
Run back through ...
On August 28 my laptop sat at 88 % disk. I deleted a 44.6 GB video intermediate I could rebuild any time. du on the folder dropped 44 GB. df on the filesystem moved 5. XFCE's thumbnailer, tumblerd, still had the file open, and a deleted file's blocks...
EADDRINUSE right after you stopped the server usually has one cause: the process you launched is not the process holding the socket. I reproduced it on my own machine with the wrapper shape npm run dev uses, a shell that starts the real server as a c...
Setting up SSH keys has a trap: every success signal can be green while the thing you cared about stays broken. ssh-copy-id exiting 0 means a line was appended to authorizedkeys — nothing more. A passwordless login afterwards means some auth method w...
A world-writable file can be rewritten by every account on the machine — including the service account your web server runs as. Code executing as www-data through a compromised plugin doesn't need root: any chmod 777 you left behind during past debug...
A 64M scratch tmpfs, a worker process holding its log open on file descriptor 3, and the usual reflex when space runs low: rm the log. du on the directory dropped from 48M to 0. df stayed at 48M used. The next 32M write failed with No space left on d...
Most "the filter looks right but the script misbehaves" bugs come down to three silent failure modes.
First, a missing -r. jq outputs JSON by default, so a string arrives with its quotes attached — your variable holds "web-01", quotes included, and ...
If grep returns empty on a file you know contains matches, suspect the pattern before the file. Default grep uses Basic Regular Expressions BRE, where |, +, ?, and are literal characters unless backslash-escaped. So grep "error|failed" app.log searc...
A demo script called report, two directories on PATH, and one mv between them, all on a scratch tmpfs:
$ report
report 2.1: 14 jobs ok
exit=0
$ mv /opt/jobs/bin/report /opt/jobs/newbin/report
$ ls -l /opt/jobs/newbin/report
rwxrwxr-x 1 root root 42 ...
The trap with rsync is that its dangerous flag combinations don't fail — they complete a different operation than the one you intended, and exit 0. --delete makes the destination match the source, so a mistyped or freshly moved source directory means...
The standard bash alerting pattern ends the same way everywhere you read it: pipe the finding into mail. So I checked what my own box would actually do with that line.
$ type -a mail mailx sendmail
mail not found
mailx not found
sendmail not found
...
I wrote four lines to capture a bash error for a guide. One empty variable, tested twice:
$ cat queue-check.sh
!/bin/bash
count=""
if $count -eq 0 ; then echo "queue empty"; fi
if $count -eq 0 ; then echo "queue empty "; fi
$ bash queue-check.sh...
Four config files, one hostname to rename. I knew the dot in api.internal is a regex wildcard, so I escaped it. grep -rn 'api.internal' unescaped matched a fourth file containing apiXinternal — a typo somebody deliberately kept. Escaped, api\.interna...
I set three log files to known ages with touch -d — exactly 30 days, 30 days and 12 hours, and 31 days — then ran what I thought was a 30-day retention policy:
find . -name '.log' -mtime +30
It returned one file: the 31-day-old one. The 30.5-day f...