change ``bash headers to ``sh

This commit is contained in:
2025-08-22 15:59:04 +02:00
parent 3e049e1687
commit 8eea348112
80 changed files with 773 additions and 555 deletions

View File

@@ -8,31 +8,31 @@ tags: [ "system", "phone" ]
Install:
```bash
```sh
yay -S simple-mtpfs
```
List available phones:
```bash
```sh
simple-mtpfs -l
```
Make a mount point:
```bash
```sh
mkdir phone
```
Check your phone, and tell it to allow access to the USB.
```bash
```sh
simple-mtpfs --device 1 phone
```
## Stop
```bash
```sh
fusermount -u phone
rmdir phone
```

View File

@@ -0,0 +1,90 @@
---
title: "Ansible Basics"
tags: [ "system", "ansible", "orchestration" ]
requires: [ "ssh" ]
---
# Start Locally
Start by doing normal actions on the computer.
Say 'hello' to yourself:
```sh
ansible --module-name=ping localhost
```
Upgrade through the package manager.
`packager=apt` (or `pacman` or `xbps`,...)
```sh
packager=apt
ansible --module-name=${packager} --args "upgrade=yes" localhost
```
This fails because you have not 'become root'.
So, '*become*'!
```sh
ansible --become -m ${packager} -a "upgrade=true" localhost
```
# Passwords
Typing the password is dull.
You might shift it to the command line:
ansible-playbook t.yaml -i hosts.yaml -e "ansible_become_password=${password}"
...this is also dull.
If you have a password store, like `pass`, you can put that in a script:
```sh
echo "#!/bin/sh
pass $HOSTNAME" > pass.sh
chmod u+x !$
ansible --become --module-name=pacman --args "upgrade=true" localhost
```
# Other Hosts
Find something you can `ssh` into.
Ansible will use your `/etc/hosts` file, and `~/.ssh/config`.
## Make a Hosts File
You can use the `.ini` format:
```sh
echo '[phones]
192.168.0.20' > hosts
```
But everything uses `yaml` nowadays, so may as well be consistent:
```yaml
all:
children:
phones:
children:
pine:
ansible_host: 192.168.0.20
```
Check the inventory in yaml format:
```sh
ansible-inventory --list -y -i
```
```sh
ansible-vault view sec.yml --vault-pass-file pass.sh
```
community.general.say voice=en_GB msg="Testing 123"

View File

@@ -8,25 +8,25 @@ See a file's contents:
Return full contents of a string:
```bash
```sh
awk '{ print }' file
```
Print the first and second column:
```bash
```sh
awk '{print$1$2}'
```
Return every line with the word 'the' (like grep):
```bash
```sh
awk '/the/{print}' file
```
Print everything containing a lowercase letter:
```bash
```sh
awk '/[a-z]/{print}' file
```
@@ -34,7 +34,7 @@ Same with numbers [0-9], or using a caret we can show lines starting with a numb
# Conditionals
```bash
```sh
awk '{ if($1 ~ /123/) print }' file
```
@@ -42,19 +42,19 @@ Check if the first column is equal to 1 or 2 or 3, and if so then print that lin
Grep for 'hawk' in a story:
```bash
```sh
awk '/hawk/' story.txt
```
Return any line with one or more "&" sequences:
```bash
```sh
awk '/&+/' script.sh
```
The pipe is used for 'or', so 'Orcs or drums' would be:
```bash
```sh
awk '/Orcs|Drums/' story.txt
```

View File

@@ -47,7 +47,7 @@ The `rm' program takes arguments, but not `stdin' from a keyboard, and therefore
To fix this, use `xargs` to turn the stdin into an argument.
For example, if we have a list of files called `list.txt' then we could use cat as so:
```bash
```sh
cat list.txt | xargs rm
```
@@ -81,13 +81,13 @@ x=$(( x*x ))
## Finding Duplicate Files
```bash
```sh
find . -type f -exec md5sum '{}' ';' | sort | uniq --all-repeated=separate -w 15 > all-files.txt
```
## Output random characters
```bash
```sh
cat /dev/urandom | tr -cd [:alnum:] | dd bs=1 count=200 status=none && echo
```
@@ -95,13 +95,13 @@ cat /dev/urandom | tr -cd [:alnum:] | dd bs=1 count=200 status=none && echo
Try something out in a random directory in `/tmp` so the files will be deleted when you next shut down.
```bash
```sh
mktemp -d
```
That gives you a random directory to mess about in.
```bash
```sh
dir=$(mktemp -d)
for x in {A..Z}; do
fortune > "$dir"/chimpan-$x

View File

@@ -1 +0,0 @@
../basics/cron.md

129
system/cron.md Normal file
View File

@@ -0,0 +1,129 @@
---
title: "cron"
tags: [ "basics", "time" ]
---
# Cronie
The `cronie` program is also known as `crond`.
## Install
```sh
sudo apt search -n ^cron
```
Once installed, search for the service name, and start it.
```sh
sudo systemctl list-unit-files | grep cron
sudo systemctl enable --now $NAME
```
## Usage
Show your current crontab:
```sh
crontab -l
```
You can put this in a file and edit it:
```sh
crontab -l > $filename
echo '39 3 */3 * * /bin/tar czf /tmp/etc_backup.tgz /etc/' >> $filename
```
Then apply that crontab:
```sh
crontab $filename
rm $filename
```
The `cron` program will check your syntax before adding the tab.
Your crontab file sits somewhere in `/var/spool/`.
Probably in `/var/spool/cron`.
## Syntax
`* * * * *`
These five points refer to:
`minute hour day month weekday`
So '3pm every Sunday' would be:
`0 15 * * 7`
Here 'Sunday' is indicated by "7", and '3pm' is 'the 15th hour'.
The minute is '0' (i.e. '0 minutes past three pm').
Doing the same thing, but only in February, would be:
`0 15 * 2 7`
### Variables
`cronie` doesn't know where you live, so to put something in your `$HOME` directory, you have to tell it:
```sh
echo "HOME=$HOME" > $filename
crontab -l >> $filename
crontab $filename
```
`cronie` doesn't know where anything lives, including programs.
You can give it your usual `$PATH` variable like this:
```sh
echo $PATH > $filename
crontab -l >> $filename
crontab $filename
```
Now instead of doing this
`40 */3 * * * /usr/bin/du -sh $HOME/* | sort -h > $HOME/sum.txt`
You can simply do this:
`40 */3 * * * du -sh $HOME/* | sort -h > $HOME/sum.txt`
## Run as Root
You can execute a script as root by putting it into a directory, instead of in the tab.
Look at the available cron directories:
```sh
ls -d /etc/cron.*
```
Make a script which runs daily:
```sh
f=apt_update.sh
echo '#!/bin/bash' > $f
echo 'apt update --yes' >> $f
chmod +x $f
sudo mv $f /etc/cron.daily/
```
### Testing with runparts
Run-parts runs all executable scripts in a directory.
```sh
run-parts /etc/cron.hourly
```
# Troubleshooting
### `date` Commands
Cron doesn't understand the `%` sign, so if you want to use `date +%R`, then it should be escaped with a backslash: `date +\%R`.

View File

@@ -7,13 +7,13 @@ tags: [ "system", "deduplicate", "maintenance", "storage" ]
Ask if a directory has duplicates (`rdfind` will not delete anything):
```bash
```sh
rdfind $dir
$EDITOR results.txt
```
Replace the duplicated files with [hard links](../basics/hard_links.md).
```bash
```sh
rdfind -makehardlinks true $dir
```

View File

@@ -9,19 +9,19 @@ Install the package `xdg-utils`, then make very liberal use of the tab button.
Ask what type of application opens an mkv file:
```bash
```sh
xdg-mime query default video/mkv
```
Same with pdf:
```bash
```sh
xdg-mime query default application/pdf
```
Ask what file-type `book.pdf` uses.
```bash
```sh
xdg-mime query filetype *book.pdf*
```
@@ -29,7 +29,7 @@ xdg-mime query filetype *book.pdf*
Set the mime type of mp4 videos to mpv.
```bash
```sh
xdg-mime default mpv.desktop video/mp4
```
@@ -37,7 +37,7 @@ You'll need to use the tab key a lot here, and remember many items start with `o
You can use an asterisk for everything in a category.
```bash
```sh
xdg-mime default org.gnome.font-viewer.desktop font/\*
```

View File

@@ -7,25 +7,25 @@ tags: [ "file browser", "TUI" ]
If you don't have a `~/.config/lf/lfrc` file, you can probably find an example in `/usr/share/examples/lf`.
```bash
```sh
cp -r /usr/share/examples/lf ~/.config/
```
Go straight to root with two keys.
```bash
```sh
map g/ cd /
```
Have lf open a file with the default program when you press 'o', using the program `mimeo`.
```bash
```sh
map o &mimeo $f
```
Change that default text editor to look at the extension first.
```bash
```sh
cmd open ${{
case $(file --mime-type $f -b) in
application/x-sc) sc-im $fx;;
@@ -52,7 +52,7 @@ That leaves it as a small initial pane, a medium pane, and a large pane for file
The standard renaming is bad, because you have to re-type the file extension.
Use this instead:
```bash
```sh
# rename current file without overwrite
cmd rename %echo 'name: ' ; read name ; extension="${f##*.}" && newname="$name.$extension"; [ "$f" = "$extension" ] && newname="$name"; [ ! -e "$newname" ] && mv "$f" "$newname" || echo file exists
map r push :rename<enter>
@@ -65,7 +65,7 @@ If you try to rename `image_1.png` with this command, you can type in `cats`, an
First, install `ueberzug` (to show images).
Then clone the lfrun repo.
```bash
```sh
git clone https://github.com/cirala/lfimg.git
cd lfimg

View File

@@ -7,7 +7,7 @@ If you have `graph-easy` (often in the package `perl-graph-easy` or similar), yo
Start with the command to 'make all targets' (`-B`), and 'do a dummy run' (`-n`) with debug into (`-d`):
```bash
```sh
make -Bnd
make -Bnd | make2graph
make -Bnd | make2graph | graph-easy --boxart

View File

@@ -7,7 +7,7 @@ tags: [ "RAID", "disk" ]
You will need 4 disks and the `mdadm` package.
The total size will be equal to the disks x 3, because one will be used for redundancy.
```bash
```sh
sudo mdadm --create --verbose /dev/*md127* --level=5 --raid-devices=*4* */dev/sdb /dev/sdc /dev/sdd /dev/sde*
```
@@ -19,7 +19,7 @@ Note the variable parts:
Now look at how the raid status:
```bash
```sh
cat /proc/mdstat
```
@@ -27,7 +27,7 @@ This will increase until the entire thing is fine.
Check the health of your `mdadm` array:
```bash
```sh
sudo mdadm --detail /dev/md127
```
@@ -35,7 +35,7 @@ You should see `State : clean`. If you see it is `degraded`, then a disk has bro
## Replacing a Disk
```bash
```sh
sudo mdadm --add /dev/md127 /dev/sdb1
```

View File

@@ -5,26 +5,26 @@ tags: [ "system", "CPU", "memory" ]
Print the average CPU load over 1 minute, 5 minutes, and 15 minutes:
```bash
```sh
watch -d cat /proc/loadavg
stress="$(cat /proc/loadavg | awk '{print "Usage:" $2"%"}')"
```
Show memory usage in Gibitytes.
```bash
```sh
free -g
```
Show low and high gigibtye usage on a *l*ine, and repeat the measurement every 5 seconds:
```bash
```sh
REP=5
free --lohi -g -s $REP | lolcat
```
Check the next thing cron will do:
```bash
```sh
cronnext /var/spool/cron/$USER -l
```

View File

@@ -6,38 +6,38 @@ tags: [ "systemd" ]
See a running log of all system messages:
```bash
```sh
journalctl -f
```
Or just one user:
```bash
```sh
journalctl --user -f
```
Or just one unit (`sshd`):
```bash
```sh
journalctl -f -u sshd
```
Find errors since November
```bash
```sh
journalctl --since=2018-11-01 --grep="EXT4-fs error"
```
Limit size to 2G.
```bash
```sh
journalctl --vacuum-size=2G
```
Log the fact that you've installed your own `dnsmasq` on your system to `journalctl`, so that you can notice why your system's broken:
```bash
```sh
logger "Installed new dnsmasq"
sudo journalctl -f
```

View File

@@ -26,7 +26,7 @@ WantedBy=multi-user.target
After making the new service, systemd requires reloading:
```bash
```sh
sudo systemctl daemon-reload
```

View File

@@ -2,33 +2,33 @@
title: "systemd"
tags: [ "systemd" ]
---
```bash
```sh
systemctl list-units
```
```bash
```sh
sudo systemctl status mpd
```
```bash
```sh
sudo systemctl daemon-reload
```
```bash
```sh
sudo systemctl taskd.service start
```
```bash
```sh
sudo systemctl status taskd.service
```
# Startup
```bash
```sh
sudo systemd-analyze
```
```bash
```sh
sudo systemd-analyze blame
```