Env-info? How?

Forum rules
We don't support installations in VirtualBox, VMWare, qemu or others. We ignore posts about WINE, PlayOnLinux, Steam and Skype. We don't support btrfs, lvm, UEFI, side-by-side installations with GPT or dualboot with anything newer than Windows XP.
Google your problem first. Check the Wiki. Read the existing threads. It's okay to "hijack" an existing thread, yes! If your problem is not yet covered, open a new thread. To get the quickest possible help, mention the exact release codename in your post (uname -a is a good idea, too). Due to the lack of crystal balls, attach the output of lspci -nnk if you encounter hardware problems.
User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Env-info? How?

Unread post by bones » Wed Nov 13, 2013 3:27 am

I've noticed on some recent screenshots that folks are using "env-info" to generate "screenfetch" or "archey"-like environment info, minus the annoying (and bloated, haha) ASCII logo. Is this a BBQ tool or script that I missed somehow? Did a search and turned up nothing.

I can haz env-info?

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Env-info? How?

Unread post by machinebacon » Wed Nov 13, 2013 3:39 am

Code: Select all

#!/bin/bash

# simple screen information script
# similar to archey and screenfetch without annoying ASCII graphics

# this script is provided with NO GUARANTEE and NO SUPPORT 
# if it breaks or does not do what you want, FIX IT YOURSELF

# wm array -- add any that need to be recognized
wms=( herbstluftwm i3 blackbox kwin awesome spectrwm matwm2 wmfs karmen fvwm cwm sithwm ratpoison evilwm xfwm4 openbox fluxbox pekwm)

# define colors for color-echo
red="\e[31m"
grn="\e[32m"
ylw="\e[33m"
cyn="\e[36m"
blu="\e[34m"
prp="\e[35m"
rst="\e[0m"    

TMP=$(mktemp)    # make temp file

color-echo() {  # print with colors
    echo -e $cyn$1': '$rst$2
}

print-kernel() {
    color-echo 'Kernel' "$(uname -smr)"
}

print-uptime() {
    up=$(</proc/uptime)
    up=${up//.*}                # string before first . is seconds
    days=$((${up}/86400))       # seconds divided by 86400 is days
    hours=$((${up}/3600%24))    # seconds divided by 3600 mod 24 is hours
    mins=$((${up}/60%60))       # seconds divided by 60 mod 60 is mins
    color-echo "Uptime" "$days"'d '"$hours"'h '"$mins"'m'
}

print-shell() {
    color-echo 'Shell' $SHELL
}

print-cpu() {
    arm=$(grep ARM /proc/cpuinfo)    # ARM procinfo uses different format
    if [ "$arm" != "" ]; then
        cpu=$(grep -m1 -i 'Processor' /proc/cpuinfo)
    else
        cpu=$(grep -m1 -i 'model name' /proc/cpuinfo)
    fi    
    color-echo 'CPU' "${cpu#*: }" # everything after colon is processor name
}

print-disk() {
    df -h / > $TMP
    total=$(awk 'NR==2 { print $2 }' $TMP) # field 2 on line 2 is total
    used=$(awk 'NR==2 { print $3 }' $TMP)  # field 3 on line 2 is used
    color-echo 'Disk' "$used / $total"
}

print-mem() {
    free -h > $TMP
    total=$(awk 'NR==2 { print $2 }' $TMP)   # field 2 on line 2 is total
    used=$(awk 'NR==3 { print $3 }' $TMP)    # field 3 on line 3 is used
    color-echo 'Mem' "$used / $total"
}

print-wm() {
    for wm in ${wms[@]}; do          # pgrep through wmname array
        pid=$(pgrep -u $USER $wm)    # if found, this wmname has running process
        if [ "$pid" ]; then
            color-echo 'WM' $wm
        fi
    done
}

print-de() {
    if [ $(pgrep -u $USER lxsession) ]; then         # if lxsession is running, assume LXDE
        color-echo 'DE' 'LXDE'
    elif [ $(pgrep -u $USER xfce4-session) ]; then   # if xfce4-session is running, assume Xfce
        color-echo 'DE' 'Xfce'
    fi
}

print-distro() {
    [[ -e /etc/os-release ]] && source /etc/os-release
    if [ -n "$PRETTY_NAME" ]; then
        color-echo 'OS' "$PRETTY_NAME"
    else
        color-echo 'OS' "not found"
    fi
}

print-colors() {
    NAMES=('black' 'red' 'green' 'yellow' 'blue' 'magenta' 'cyan' 'white')
    for f in $(seq 0 7); do
        echo -en "\033[m\033[$(($f+30))m ${NAMES[$f]} " # normal colors
    done
    echo	
    for f in $(seq 0 7); do
        echo -en "\033[m\033[1;$(($f+30))m ${NAMES[$f]} " # bold colors
    done
    echo -e "$rst\n"
}

echo -e '\n'$prp$USER'@'$HOSTNAME$rst'\n'   # print user and host name
print-distro
print-uptime
print-shell
print-de
print-wm
print-disk
print-mem
print-kernel
print-cpu
echo
print-colors

rm $TMP     # delete temp file
Courtesy of Pidsley.
..gnutella..

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Env-info? How?

Unread post by bones » Wed Nov 13, 2013 4:38 am

^Nice, thanks. I'll probably modify to omit the colors, I'm just not finding myself in "interior designer" mode like the rest of you girls. ;) *smooch*

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Env-info? How?

Unread post by pidsley » Wed Nov 13, 2013 6:05 am

There is a slightly more recent version (minus the temp file and plus all the window managers) here: https://github.com/pidsley/codemangler

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Env-info? How?

Unread post by bones » Wed Nov 13, 2013 2:10 pm

^Thanks, pids!

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Env-info? How?

Unread post by bones » Wed Nov 13, 2013 10:19 pm

With some modifications, I've got the env-info script going on my slackbox here at work. I had to modify the following:

Code: Select all

print-mem() {
    # field 2 on line 2 is total, field 3 on line 3 is used
    mem=$(free -h | awk 'NR==2 {total=$2} NR==3 {used=$3; print used" / "total}')
    color-echo 'Mem' "$mem"
To read instead:

Code: Select all

print-mem() {
    # field 2 on line 2 is total, field 3 on line 3 is used
    mem=$(free -m | awk 'NR==2 {total=$2} NR==3 {used=$3; print used" / "total}')
    color-echo 'Mem' "$mem"
To get it to work properly in Slackware. Also commented out "print colors" per Pidsley's instructions, to get rid of the color info.

Screenshot or it didn't happen.
Screenshot - 11132013.png
Edit: Mem line still needs tweaking, not displaying RAM (M or G) at all.

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Env-info? How?

Unread post by rhowaldt » Wed Nov 13, 2013 10:57 pm

hmm, different version of 'mem' on Slackware? the same problem might be with the RAM display?
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
wuxmedia
Grasshopper
Posts: 6454
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: Env-info? How?

Unread post by wuxmedia » Wed Nov 13, 2013 11:05 pm

it's seemingly using 'free', try 'free -mh' that appends a 'G' or 'M' to the end, awk should pick up the whole field.
or do you mean it's not the right numbers?

oh, how come free -h didn't work?
it's not a solaris/freebsd/windows version or something wacky?
"Seek, and Ye shall find"
"Github | Chooons | Site"

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Env-info? How?

Unread post by bones » Wed Nov 13, 2013 11:13 pm

Here's what it looked like prior to my change:
Screenshot.png
I will try your suggestion, wux.

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Env-info? How?

Unread post by bones » Wed Nov 13, 2013 11:24 pm

Ok, wux's didn't work, but pid's did:

mem=$(free -m | awk 'NR==2 {total=$2} NR==3 {used=$3; print used"M / "total"M"}')
Attachments
Screenshot_3.png

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Env-info? How?

Unread post by pidsley » Wed Nov 13, 2013 11:35 pm

Apparently not all distros support "free -h" -- just all the ones I tested. :(

"free -m" works (and it's actually what I was using a few versions ago, before I decided "free -h" was prettier). /closed :)

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: Env-info? How?

Unread post by rhowaldt » Wed Nov 13, 2013 11:41 pm

just one little thing, and you can call me an OCD-motherfucker. but free -V will show you the version of 'free' so we can determine whether it is actually just a different one... i'm curious as to whether Slackware has an older or newer version or something else is going on here.

Code: Select all

[23:40:47]$ free -V
free from procps-ng 3.3.4
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Env-info? How?

Unread post by pidsley » Wed Nov 13, 2013 11:48 pm

all the distros I tested have free from the procps-ng package

3.3.8 in sid
3.3.3 in Wheezy
3.3.8 in Arch
3.3.8 in LFS
3.3.8 in CRUX

This page says procps-ng is a fork of procps, so maybe(probably) Slack has original procps?
https://sourceforge.net/projects/procps-ng/

User avatar
bones
Clooney
Posts: 2385
Joined: Fri Jun 28, 2013 11:47 pm
Location: Cascadia

Re: Env-info? How?

Unread post by bones » Thu Nov 14, 2013 12:04 am

Indeed:

Code: Select all

procps version 3.2.8
Of course Slackware would be kickin' it old school. ;)

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: Env-info? How?

Unread post by machinebacon » Thu Nov 14, 2013 1:11 am

I can confirm that -h (human-readable it is called, I think) has not worked a few versions ago, when I was still with aptosid, for sure. Guess we have the awk/mawk/gawk situation here, too.
..gnutella..

pidsley
Hermit
Posts: 2539
Joined: Wed Oct 17, 2012 12:31 pm

Re: Env-info? How?

Unread post by pidsley » Thu Nov 14, 2013 1:18 am

Ok then. Anyone who has this problem can use

mem=$(free -m | awk 'NR==2 {total=$2} NR==3 {used=$3; print used"M / "total"M"}')

I probably won't change the script on github. But I might. :)

Post Reply