Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
show emerge logs of whatever is being compiled
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Sun Oct 10, 2021 9:07 pm    Post subject: show emerge logs of whatever is being compiled Reply with quote

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
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21607

PostPosted: Sun Oct 10, 2021 9:56 pm    Post subject: Re: show emerge logs of whatever is being compiled Reply with quote

kris0 wrote:
Code:
#!/bin/sh
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.
kris0 wrote:
Code:
  exec sudo $0 $@
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
View user's profile Send private message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Sun Oct 10, 2021 10:48 pm    Post subject: Reply with quote

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 :wink:
Back to top
View user's profile Send private message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Sun Oct 10, 2021 11:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Sun Oct 10, 2021 11:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30894
Location: here

PostPosted: Mon Oct 11, 2021 5:06 am    Post subject: Reply with quote

In guru overlay there is a similar utility app-portage/showbuild.
_________________
Questions are guaranteed in life; Answers aren't.
Back to top
View user's profile Send private message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Mon Oct 11, 2021 3:31 pm    Post subject: Reply with quote

Thanks fedeliallalinea,

https://git.nju.edu.cn/ti/guru/-/blob/master/app-portage/showbuild/files/showbuild-0.9.1 is the git repo I think, https://github.com/junghans/cj-overlay doesn't seem to exist
Back to top
View user's profile Send private message
fedeliallalinea
Administrator
Administrator


Joined: 08 Mar 2003
Posts: 30894
Location: here

PostPosted: Mon Oct 11, 2021 4:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Mon Oct 11, 2021 4:37 pm    Post subject: Reply with quote

Settled on this: https://github.com/kris004/emergeBuildLogs/blob/main/ses
Back to top
View user's profile Send private message
cboldt
Veteran
Veteran


Joined: 24 Aug 2005
Posts: 1046

PostPosted: Mon Oct 11, 2021 7:15 pm    Post subject: Reply with quote

Code:
less $(ls /var/log/portage -t | head -1)


Depends on setting up $PORT_LOGDIR
Back to top
View user's profile Send private message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Mon Oct 11, 2021 7:30 pm    Post subject: Reply with quote

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
View user's profile Send private message
cboldt
Veteran
Veteran


Joined: 24 Aug 2005
Posts: 1046

PostPosted: Mon Oct 11, 2021 8:36 pm    Post subject: Reply with quote

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
View user's profile Send private message
spica
Apprentice
Apprentice


Joined: 04 Jun 2021
Posts: 285

PostPosted: Mon Oct 11, 2021 8:51 pm    Post subject: Reply with quote

Code:
find /var/tmp/portage/*/*/temp/build.log -type f | xargs tail -f | perl -pe 's;^(.{120}).+;$1;'
Back to top
View user's profile Send private message
kris0
n00b
n00b


Joined: 10 Oct 2021
Posts: 16

PostPosted: Mon Oct 11, 2021 9:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
cboldt
Veteran
Veteran


Joined: 24 Aug 2005
Posts: 1046

PostPosted: Mon Oct 11, 2021 9:26 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum