View previous topic :: View next topic |
Author |
Message |
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
Posted: Sun Oct 10, 2021 9:07 pm Post subject: show emerge logs of whatever is being compiled |
|
|
I wanted to make it easier to see logs of whatever emerge is currently compiling so I wrote this script, anyone do something simliar/better?
Code: |
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
exec sudo $0 $@
fi
for CATAGORY in $(ls /var/tmp/portage); do
for PROGRAM in $(ls /var/tmp/portage/${CATAGORY}); do
export BUILD_LIST="${BUILD_LIST} ${CATAGORY}/${PROGRAM}"
done
done
test -z "$BUILD_LIST" && exit 0
export BUILD_LIST=$(echo ${BUILD_LIST} | tr ' ' '\n')
echo "${BUILD_LIST}" | nl
printf 'Select build number: '
read n; echo
export build="$(echo "${BUILD_LIST}" | sed -n "${n}p")"
trap 'echo got SIGINT' 2
less +F /var/tmp/portage/${build}/temp/build.log
trap - 2
exit 0
|
|
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 22730
|
Posted: Sun Oct 10, 2021 9:56 pm Post subject: Re: show emerge logs of whatever is being compiled |
|
|
No set -eu, on principle? kris0 wrote: | Code: | if [ "$(id -u)" -ne 0 ]; then |
| If you assume bash, rather than basic sh, you can use $EUID here.You should quote $@. kris0 wrote: | Code: | for CATAGORY in $(ls /var/tmp/portage); do
for PROGRAM in $(ls /var/tmp/portage/${CATAGORY}); do |
| Using ls is usually wrong. A simple glob would suffice here, I think. Code: | set -- "${PORTAGE_TMPDIR:-/var/tmp/portage}"/*/*
[[ $# -eq 0 ]] && exit 0 | This saves you repeated invocations of ls, and places the build list in a variable for later use. kris0 wrote: | Code: | export BUILD_LIST="${BUILD_LIST} ${CATAGORY}/${PROGRAM}" |
| Why do you export this? It seems to only be needed internally.
kris0 wrote: | Code: | export BUILD_LIST=$(echo ${BUILD_LIST} | tr ' ' '\n') |
| This is unnecessary with the set I propose.
kris0 wrote: | Code: | echo "${BUILD_LIST}" | nl |
| With set, this could be rewritten as: Code: | (IFS=$'\n'; exec cat -n <<< "$*") |
kris0 wrote: | Code: | printf 'Select build number: '
read n; |
| This could be condensed via use of read -p.
kris0 wrote: | Code: | export build="$(echo "${BUILD_LIST}" | sed -n "${n}p")" |
| If the parameters are in an array, this can be done without a shell out. Code: | $ (set -- a b c; a=2; echo "${!a}")
b |
kris0 wrote: | Code: | trap 'echo got SIGINT' 2 |
| Why? kris0 wrote: | Code: | less +F /var/tmp/portage/${build}/temp/build.log |
| Why not just exec less here? |
|
Back to top |
|
|
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
Posted: Sun Oct 10, 2021 10:48 pm Post subject: |
|
|
Hey Hu, thanks for taking the time to go through that. I like the usage of set for sure. This all seems reasonable to me, a lot of it won't work because I am using yash as /bin/sh and want to try to keep it POSIX. I was very surprised when globbing didn't work for the filesystem, ls was the expedient solution but ugly.
I'm pretty sure I used export because I was recovering from a scaring experience debugging an old/broken/terrible version of bash that required it and typed it out of reflex.
I didn't exec less because I had a vague idea to allow you to select a different log after exiting less, but got distracted by less requiring you to ^c in order to exit readahead which is also why I'm catching sigints so it won't exit the script when you exit readahead in less. That being said exec makes more sense as presented!
I don't often share scripts so I'm very grateful for the feedback I'm sure I need it |
|
Back to top |
|
|
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
Posted: Sun Oct 10, 2021 11:42 pm Post subject: |
|
|
Using dash globbing works fine, updated with some of Hu's comments:
Code: |
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
exec sudo $0
fi
set -- "${PORTAGE_TMPDIR:-/var/tmp/portage}"/*/*
test -z "$1" && exit 0
echo "$@" | tr ' ' '\n' | nl
while :; do
printf 'Select build number: '
read n; echo
build=$(echo "$@" | awk "{print \$$n}")
trap '' 2
less +F ${build}/temp/build.log
trap - 2
done
|
|
|
Back to top |
|
|
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
Posted: Sun Oct 10, 2021 11:48 pm Post subject: |
|
|
Better yet:
Code: |
#!/bin/sh
if [ "$(id -u)" -ne 0 ]; then
exec sudo $0
fi
set -- "${PORTAGE_TMPDIR:-/var/tmp/portage}"/*/*
test -z "$1" && exit 0
echo "$@" | tr ' ' '\n' | nl
while :; do
printf 'Select build number: '
read n; echo
trap '' 2
eval less +F \$$n/temp/build.log
trap - 2
done
|
|
|
Back to top |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 31284 Location: here
|
|
Back to top |
|
|
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
|
Back to top |
|
|
fedeliallalinea Administrator
Joined: 08 Mar 2003 Posts: 31284 Location: here
|
Posted: Mon Oct 11, 2021 4:00 pm Post subject: |
|
|
An overlay (e.g.https://github.com/junghans/cj-overlay) is an ebuild repository that usually contains ebuild not present in official tree.
You can add it with eselect repository. _________________ Questions are guaranteed in life; Answers aren't. |
|
Back to top |
|
|
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
|
Back to top |
|
|
cboldt Veteran
Joined: 24 Aug 2005 Posts: 1046
|
Posted: Mon Oct 11, 2021 7:15 pm Post subject: |
|
|
Code: | less $(ls /var/log/portage -t | head -1) |
Depends on setting up $PORT_LOGDIR |
|
Back to top |
|
|
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
Posted: Mon Oct 11, 2021 7:30 pm Post subject: |
|
|
cboldt wrote: | less $(ls /var/log/portage -t | head -1) |
I see where your going here, it would be useful if your not doing parallel builds. Though maybe have to use find instead of ls to get full paths? |
|
Back to top |
|
|
cboldt Veteran
Joined: 24 Aug 2005 Posts: 1046
|
Posted: Mon Oct 11, 2021 8:36 pm Post subject: |
|
|
oh yeah ... I cut and pasted the wrong one!
Code: | less $(ls /var/log/portage/* -t | head -1) |
Good point if there is more than one emerge at a time. I generally use -q switch on emerge, so when I do want to watch what's happening, I have to find the log and tail it. I just do a `ls -rt /var/log/portage/*` and pick the last one. If I was doing parallel builds, then the info would still be on the screen for cut (double left click) and paste (middle click) job.
Not critical of your script, BTW. You asked about ways to view running job, and my way is the ls / less way. |
|
Back to top |
|
|
spica Guru
Joined: 04 Jun 2021 Posts: 330
|
Posted: Mon Oct 11, 2021 8:51 pm Post subject: |
|
|
Code: | find /var/tmp/portage/*/*/temp/build.log -type f | xargs tail -f | perl -pe 's;^(.{120}).+;$1;' |
|
|
Back to top |
|
|
kris0 n00b
Joined: 10 Oct 2021 Posts: 16
|
Posted: Mon Oct 11, 2021 9:21 pm Post subject: |
|
|
cboldt wrote: | Not critical of your script, BTW. You asked about ways to view running job, and my way is the ls / less way. |
No worries, this is exactly what I was looking for. I'm trying to get out of my linux silo and see how other people do things.
spica wrote: | Code: | find /var/tmp/portage/*/*/temp/build.log -type f | xargs tail -f | perl -pe 's;^(.{120}).+;$1;' |
| Nice! |
|
Back to top |
|
|
cboldt Veteran
Joined: 24 Aug 2005 Posts: 1046
|
Posted: Mon Oct 11, 2021 9:26 pm Post subject: |
|
|
I have few packages where the build is too large to fit in tmpfs, so the build is not done in /var/tmp/portage. I use files in /etc/portage/env and /etc/portage/package.env to set PORTAGE_TMPDIR to a different value.
So, for those, build.log is in a different place.
The may be a way to capture this, for those who choose to operate without a PORT_LOGDIR and also vary PORTAGE_TMPDIR to accommodate limited RAM. |
|
Back to top |
|
|
|