}
aw() {
pushd /a/work/ans >/dev/null
- time ansible-playbook -v -i inventory adhoc.yml "$@"
+ time ansible-playbook -i inventory adhoc.yml "$@"
popd >/dev/null
}
ad() {
install-my-scripts
# todo: consider changing this to srun and having the args come
# from a file like /etc/default/btrbk, like is done in exim
- s jrun btrbk-run "$@"
+ s jdo btrbk-run "$@"
if $active; then
if (( ret )); then
echo bbk: WARNING: btrbk.timer not restarted due to failure
ngreset
}
-# duplicated somewhat below.
-jrun() { # journal run. run args, log to journal, tail and grep the journal.
- # Note, an alternative without systemd would be something like ts.
- # Note, I tried using systemd-cat, but this seems obviously better,
- # and that seemed to have a problem exiting during a systemctl daemon-reload
- local cmd_name jr_pid s
+scr() {
+ screen -RD "$@"
+}
+
+
+# version of jdo for my non-root user
+jdo() {
+ # comparison of alternative logging methods:
+ #
+ # systemd-run command (what this function does)
+ #
+ # If there is a user prompt, the program will detect that it is not
+ # connected to a terminal and act in a non-interactive way, skipping
+ # the prompt. This has the benefit that you know exactly how the
+ # program will act if you want to move it into a service that runs
+ # automatically.
+ #
+ # If run with sudo and command is a shell script which does a sleep,
+ # it can (sometimes?) output some extra whitespace in front of
+ # messages, more for each subsequent message. This can be avoided by
+ # becoming root first.
+ #
+ # It logs the command's pid and exit code, which is nice.
+ #
+ #
+ ### command |& ts | tee file.log
+ #
+ # If there is a user prompt, like "read -p prompt var", it will hang
+ # without outputting the prompt.
+ #
+ # I've had a few times where ts had an error and I wasn't totally sure
+ # if it was really the command or ts having the problem.
+ #
+ # Sometimes some output will get hidden until you hit enter.
+ #
+ #
+ ### command |& pee cat logger
+ #
+ # This seems to work. I need to test more.
+ #
+ #
+ ### command |& logger -s
+ #
+ # User prompts get confusingly prefixed to earlier output, and all log
+ # entries get prefixed with annoying priority level.
+ #
+ #
+ ### systemd-cat
+ #
+ # Had a few problems. One major one is that it exited in the middle of
+ # a command on systemctl daemon-reload
+ #
+ # Related commands which can log a whole session: script, sudo, screen
+ local cmd cmd_name jr_pid ret
ret=0
- cmd_name=${1##*/}
- cmd=$1
+ cmd="$1"
+ shift
+ cmd_name=${cmd##*/}
if [[ $cmd != /* ]]; then
- cmd=$(which $1)
+ cmd=$(type -P "$cmd")
fi
+ # -q = quiet
journalctl -qn2 -f -u "$cmd_name" &
- # Guess of time needed to avoid missing initial lines.
+ # Trial and error of time needed to avoid missing initial lines.
# .5 was not reliable. 1 was not reliable. 2 was not reliable
sleep 4
- # We kill this in prompt-command for the case that we ctrl-c the
- # systemd-cat. i dont know any way to trap ctrl-c and still run the
- # normal action for it. There might be a way, unsure.
jr_pid=$!
# note, we could have a version that does system --user, but if for example
# it does sudo ssh, that will leave a process around that we can't kill
# and it will leave the unit hanging around in a failed state needing manual
# killing of the process.
- m s systemd-run --uid $(id -u) --gid $(id -g) \
+ s systemd-run --uid $(id -u) --gid $(id -g) \
-E SSH_AUTH_SOCK=/run/openssh_agent \
- --unit "$cmd_name" --wait --collect "$cmd" "${@:2}" || ret=$?
- # This justs lets the journal output its last line
+ --unit "$cmd_name" --wait --collect "$cmd" "$@" || ret=$?
+ # The sleep lets the journal output its last line
# before the prompt comes up.
sleep .5
kill $jr_pid &>/dev/null ||:
unset jr_pid
fg &>/dev/null ||:
+ # this avoids any err-catch
+ (( $ret == 0 )) || return $ret
}
+
# service run, and watch the output
srun() {
local unit
s ssh-add /root/.ssh/home
fi
install-my-scripts
- s jrun switch-mail-host "$@"
+ s jdo switch-mail-host "$@"
return $ret
}
sh2() { # switch host2
s ssh-add /root/.ssh/home
fi
install-my-scripts
- s jrun switch-host2 "$@"
+ s jdo switch-host2 "$@"
return $ret
}
ssh root@iankelling.org "cd $d; find . -mtime -60 -type f -exec grep '\<iank.*' {} +" | sed -r 's,^..([^/]*)/(.{11})(.{5})(.{8}).,\2\4 \1,' | sort
}
+# usage: debvm DEBIAN_VERSION RAM_MB
+debvm() {
+ local ver ram fname src
+ ver=$1
+ ram=${2:-2024}
+ # * is because it might have -backports in the name
+ fname=debian-$ver-*nocloud-$(dpkg --print-architecture).qcow2
+ src=/a/opt/roms/$fname
+ if [[ ! -f $src ]]; then
+ echo debvm: not found $src, download from eg: https://cloud.debian.org/images/cloud/buster/latest/
+ return 1
+ fi
+ cp -a $src /t
+ # note, in fai-revm we do this: not sure why, maybe because of br device
+ # --graphics spice,listen=0.0.0.0
+ m s virt-install --osinfo debian11 --rng /dev/urandom -n deb${ver}tmp --import -r $ram --vcpus 2 --disk /t/$fname --graphics spice
+ # note: to ssh into this machine will require host key generation: ssh-keygen -A
+
+ # random: for cvs2git on gnu www, use debian 10. I could use trisquel,
+ # but happen to want to try out the debian cloud images. the upstream
+ # requires python2 and hasn't really changed since the version in d10.
+ #
+ # apt install cvs2git cvs
+ # # 7G was not enough
+ # mount -o mode=1777,nosuid,nodev,size=34G -t tmpfs tmpfs /tmp
+ # cvs2git --encoding utf_8 --fallback-encoding ascii --dumpfile=dump www-rsync/www |& tee /tmp/l
+ ## www-rsync is an rsynced copy of the cvsfrom savannah
+}
+
mygajim() {
local time time_sec time_pretty days
days=${1:-16}
}
+# very useful, copy directory structure 3 deep. add remove /*/ to change level
+# rsync -aivh --exclude '/*/*/*/' -f"+ */" -f"- *" SRC DEST
+
+
# * stuff that makes sense to be at the end
if [[ "$SUDOD" ]]; then
# allow failure, for example if we are sudoing into a user with diffferent/lesser permissions.