# journalctl -f FINAL_ARG, then systemctl $@ .
# detects any existing background job so we can
-# run multiple times without making duplicate output.
+# run multiple times without making duplicate output. todo: not right now.
serj() {
- local service jr_pid ret jobs_out regex
+ local service jr_pid ret regex tmpstr found_job
+ local -a jobs_out
ret=0
service="${*: -1}"
- jobs_out=$(jobs 2>/dev/null)
- regex="^[^[:space]]+[[:space:]]+Running[[:space:]]+ journalctl -qn2 -f -u $service &"
+ tmpstr=$(jobs 2>/dev/null)
+ mapfile -t jobs_out <<<"$tmpstr"
+ found_job=false
+ regex="^[^[:space:]]+[[:space:]]+Running[[:space:]]+ journalctl --since=now -qn2 -f -u $service &"
+ for line in "${jobs_out[@]}"; do
+ if [[ $line =~ $regex ]]; then
+ found_job=true
+ fi
+ done
- journalctl -qn2 -f -u "$service" &
- sleep 3
- s systemctl "$@" || ret=$?
+ if ! $found_job; then
+ journalctl --since=now -qn2 -f -u "$service" &
+ sleep 3
+ fi
+ if [[ $EUID == 0 ]]; then
+ systemctl "$@" || ret=$?
+ else
+ # it adds like 50 chars of whitespace to each log line without
+ # --no-block. its some interaction with sudo i guess?
+ s systemctl --no-block "$@" || ret=$?
+ fi
if (( ret != 0 )); then
echo "serj: note: systemctl returned nonzero, but journalctl worked and is running."
return $ret
if [[ ! -e $status_file || -w $status_file ]]; then
if [[ -e /a/bin/bash_unpublished/source-state ]]; then
cat /a/bin/bash_unpublished/source-state >$status_file
+ else
+ sed -i --follow-symlinks '/^ps_char=/d' $status_file
fi
if [[ ${chars[*]} ]]; then