Script failures - User Error copy from source <SOLVED>

interpretive language scripts


Moderator: Forum moderators

Post Reply
Clarity
Posts: 3888
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1643 times
Been thanked: 528 times

Script failures - User Error copy from source <SOLVED>

Post by Clarity »

I was reviewing this YAD example script as a simple system utility.

Tiny-sysinfo.png
Tiny-sysinfo.png (60.13 KiB) Viewed 880 times

But when I execute it I am getting an error with variables and other lines that I cannot pin-point.

Code: Select all

# YADtest-sysinfo.sh
/root/my-applications/bin/YADtest-sysinfo.sh: line 4: YAD_OPTIONS: command not found
/root/my-applications/bin/YADtest-sysinfo.sh: line 6: KEY: command not found
/root/my-applications/bin/YADtest-sysinfo.sh: line 32: syntax error near unexpected token `('
/root/my-applications/bin/YADtest-sysinfo.sh: line 32: `lspci -vmm | sed  's/\&/\&/g' | grep  -E  "^(Slot|Class|Vendor|Device|Rev):" | cut -f2 |\'
# Unable to parse command line: Cannot parse integer value “=” for --plug

The web-page I copied from is above. My copy of that is here

Code: Select all

#! /bin/bash 
# -*- mode: sh -*- 

YAD_OPTIONS = "--window-icon='dialog-information' --name=IxSysinfo" 

KEY = $RANDOM 

function show_mod_info { 
TXT = " \\ n<span face='Monospace'>$(modinfo  $1  | sed 's/&/\&/g;s/</\</g;s/>/\>/g' )</span>" 
yad --title = $ "Module information"  --button = "yad-close"  --width = 500 \
--image = "application-x-addon"  --text = " $ TXT " 
} 
export -f show_mod_info

# CPU tab 
lscpu | sed  -r  "s/:[ ]*/ \n /" |\
yad --plug = $KEY  --tabnum = 1  --image = cpu --text = $ "CPU information" \
--list - -no-selection --column = $ "Parameter"  --column = $ "Value"  & 

# Memory tab 
sed  -r  "s/:             
22 23 , $7 , $2 , $3 , $4 , $6 }' |\ yad --plug = $KEY --tabnum = 3 --image = drive-harddisk --text = $ "Disk space usage" \ --list - -no-selection --column = $ "Device" --column = $ "Mountpoint" --column = $ "Type" \ --column = $ "Total:sz" --column = $ "Free:sz" --column = $ "Usage:bar" & # PCI tab lspci -vmm | sed 's/\&/\&/g' | grep -E "^(Slot|Class|Vendor|Device|Rev):" | cut -f2 |\ yad --plug = $KEY --tabnum = 4 --text = $ "PCI bus devices" \ --list --no-selection --column = $ "ID" --column = $ "Class" \ --column = $ "Vendor" --column = $ "Device" --column = $ "Rev" & # Modules tab awk '{printf "%s \n %s \n %s \n ", $1 , $3 , $4 }' / proc / modules | sed "s/[, --column = $ "Used" --column = $ "Depends" & # Battery tab ( acpi -i ; acpi -a ) | sed -r "s/:[ ]*/ \n /" | yad --plug = $KEY --tabnum = 6 \ --image = battery --text = $ "Battery state" --list --no-selection \ --column = $ "Device" --column = $ "Details" & # Sensors tab SENSORS =( $ ( sensors | grep -E '^[^:]+$' )) sid = 1 cid = 1 for s in ${SENSORS[@ ]} ; do echo -e "s $sid\n <b> $s </b> \n " sensors -A " $s " | tail -n + 2 | while read ln ; do [[ $ln == "" ]] && continue echo " $cid :s $sid " echo $ln | sed -r 's/:[ ]+/ \n /' (( cid ++)) done (( sid ++)) done | yad - -plug = $KEY --tabnum = 7 --text = $ "Temperature sensors information" \ --list --tree --tree-expanded --no-selection --column = $ "Sensor" --column = $ "Value" & # main dialog TXT = $ "<b>Hardware system information</b> \\ n \\ n" TXT += $ " \\ tOS: $(lsb_release -ds) on $ (hostname) \\ n" TXT += $ " \\ tKernel:$(uname -sr) \\ n \\ n" TXT += " \\ t<i>$(uptime)</i>" yad --notebook --width = 600 --height = 450 - -title = $ "System info" --text = " $TXT " --button = "yad-close" \ --key = $KEY --tab = $ "CPU" --tab = $ "Memory" - -tab = $ "Disks" --tab = $ "PCI" --tab = $ "Modules" \ --tab = $ "Battery" --tab = $ "Sensors" --active-tab = ${1:-1}

I cant see if something copied over wrong or if command use is wrong or ??? But, I think its an error that I created somehow.

Help in what I did wrong.

Last edited by Clarity on Fri Mar 01, 2024 6:35 am, edited 1 time in total.
User avatar
mikewalsh
Moderator
Posts: 6185
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 803 times
Been thanked: 1994 times

Re: Script failures - I have a script where variables are not setting.

Post by mikewalsh »

@Clarity :-

I cant see if something copied over wrong or if command use is wrong or ??? But, I think its an error that I created somehow.

Nah. I doubt it. Some of those errors are a bit of a giveaway...

What version of YAD d'you have installed in.....Slacko 7, I believe you use most? Pounds to peanuts it's an older version, and YAD's age plays a big part in this; newer builds came with a lot of additional capabilities that older builds simply didn't possess, and Micko's Pups often came with older, rather conservative dependencies.

If you enter

Code: Select all

yad --about

.....what do you get?

Mike.Image

williwaw
Posts: 1973
Joined: Tue Jul 14, 2020 11:24 pm
Has thanked: 172 times
Been thanked: 372 times

Re: Script failures - I have a script where variables are not setting.

Post by williwaw »

extra spaces?
compare your line 6 to the example line 5 etc.

User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: Script failures - I have a script where variables are not setting.

Post by MochiMoppel »

Clarity wrote: Fri Mar 01, 2024 2:40 am

I cant see if something copied over wrong or if command use is wrong or ???

Indeed lots of extra spaces. How did you copy?
I just copied the code from the web site into Geany, then removed the first 6 characters from each line (= the margin containing the line numbers) and then executed. Works fine.

Clarity
Posts: 3888
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1643 times
Been thanked: 528 times

Re: Script failures - I have a script where variables are not setting.

Post by Clarity »

Thanks @mikewalsh I am using this from BKWP64

Distro Package Managers(1).jpg
Distro Package Managers(1).jpg (7.49 KiB) Viewed 860 times

.

Thanks @williwaw I remove spaces on variable assignment in line 4+6 to get the following, now. Have NOT changed any others as they all appear to be yad/sed parm assignments. Results:

Code: Select all

# yad --about  # advice from MikeWalsh
# Echo "remove spaces in variable assignments and rerun the script" # advice from Williwaw
remove spaces in variable assignments and rerun the script
# YADtest-sysinfo.sh
/root/my-applications/bin/YADtest-sysinfo.sh: line 30: syntax error near unexpected token `('
/root/my-applications/bin/YADtest-sysinfo.sh: line 30: `lspci -vmm | sed  's/\&/\&/g' | grep  -E  "^(Slot|Class|Vendor|Device|Rev):" | cut -f2 |\'
# Unable to parse command line: Cannot parse integer value “=” for --plug
^C
# 

Question
Should the spaces for the parms in SED/AWK/YAD be removed also for those commands to work?
.

@MochiMoppel Is there any possibility that you could post your copy? I did what you suggested to start AND is how I arrived at my posted script (except changing from sh to bash).
Please, if you do, I will run diff to determine what went wrong.

Thanks in advance everyone.

User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: Script failures - I have a script where variables are not setting.

Post by MochiMoppel »

Clarity wrote: Fri Mar 01, 2024 4:32 am

@MochiMoppel Is there any possibility that you could post your copy? I did what you suggested to start AND is how I arrived at my posted script (except changing from sh to bash).
Please, if you do, I will run diff to determine what went wrong.

Code: Select all

#! /bin/sh
# -*- mode: sh -*-

YAD_OPTIONS="--window-icon='dialog-information' --name=IxSysinfo"

KEY=$RANDOM

function show_mod_info {
    TXT="\\n<span face='Monospace'>$(modinfo $1 | sed 's/&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g')</span>"
    yad --title=$"Module information" --button="yad-close" --width=500 \
        --image="application-x-addon" --text="$TXT"
}
export -f show_mod_info

# CPU tab
lscpu | sed -r "s/:[ ]*/\n/" |\
    yad --plug=$KEY --tabnum=1 --image=cpu --text=$"CPU information" \
        --list --no-selection --column=$"Parameter" --column=$"Value" &

# Memory tab
sed -r "s/:[ ]*/\n/" /proc/meminfo |\
    yad --plug=$KEY --tabnum=2 --image=memory --text=$"Memory usage information" \
        --list --no-selection --column=$"Parameter" --column=$"Value" &

# Harddrive tab
df -T | tail -n +2 | awk '{printf "%s\n%s\n%s\n%s\n%s\n%s\n", $1,$7, $2, $3, $4, $6}' |\
    yad --plug=$KEY --tabnum=3 --image=drive-harddisk --text=$"Disk space usage" \
        --list --no-selection --column=$"Device" --column=$"Mountpoint" --column=$"Type" \
        --column=$"Total:sz" --column=$"Free:sz" --column=$"Usage:bar" &

# PCI tab
lspci -vmm | sed 's/\&/\&amp;/g' | grep -E "^(Slot|Class|Vendor|Device|Rev):" | cut -f2 |\
    yad --plug=$KEY --tabnum=4 --text=$"PCI bus devices" \
        --list --no-selection --column=$"ID" --column=$"Class" \
        --column=$"Vendor" --column=$"Device" --column=$"Rev" &

# Modules tab
awk '{printf "%s\n%s\n%s\n", $1, $3, $4}' /proc/modules | sed "s/[,-]$//" |\
    yad --plug=$KEY --tabnum=5 --text=$"Loaded kernel modules" \
        --image="application-x-addon" --image-on-top \
        --list --dclick-action='bash -c "show_mod_info %s"' \
        --column=$"Name" --column=$"Used" --column=$"Depends" &

# Battery tab
( acpi -i ; acpi -a ) | sed -r "s/:[ ]*/\n/" | yad --plug=$KEY --tabnum=6 \
    --image=battery --text=$"Battery state" --list --no-selection \
    --column=$"Device" --column=$"Details" &

# Sensors tab
SENSORS=($(sensors | grep -E '^[^:]+$'))
sid=1
cid=1

for s in ${SENSORS[@]}; do
    echo -e "s$sid\n<b>$s</b>\n"
    sensors -A "$s" | tail -n +2 | while read ln; do
        [[ $ln == "" ]] && continue
        echo "$cid:s$sid"
        echo $ln | sed -r 's/:[ ]+/\n/'
        ((cid++))
    done
    ((sid++))
done | yad --plug=$KEY --tabnum=7 --text=$"Temperature sensors information" \
    --list --tree --tree-expanded --no-selection --column=$"Sensor" --column=$"Value" &

# main dialog
TXT=$"<b>Hardware system information</b>\\n\\n"
TXT+=$"\\tOS: $(lsb_release -ds) on $(hostname)\\n"
TXT+=$"\\tKernel: $(uname -sr)\\n\\n"
TXT+="\\t<i>$(uptime)</i>"

yad --notebook --width=600 --height=450 --title=$"System info" --text="$TXT" --button="yad-close" \
    --key=$KEY --tab=$"CPU" --tab=$"Memory" --tab=$"Disks" --tab=$"PCI" --tab=$"Modules" \
    --tab=$"Battery" --tab=$"Sensors" --active-tab=${1:-1}

I suggest that for testing you copy only a few lines and see what the result looks like. E.g. there should be no space after YAD_OPTIONS, I remember that - long time ago - text copied from the Opera browser included extra spaces. Maybe it's a browser issue. I'm using LibreWolf.

Maybe unrelated but I also noticed that I didn't receive a notification although you mentioned me in your post (of course assuming that you used the [mention] tag)

Clarity
Posts: 3888
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1643 times
Been thanked: 528 times

Script failures - User Error copy from source <SOLVED>

Post by Clarity »

Thanks VERY Much, @MochiMoppel
I made my copy via a cut-paste directly from the webpage into Geany on my BKWP64 v10.0.5

I copied your version from this thread and ran an immediate test of your version. Results

Code: Select all

YADtest-sysinfo.sh
/root/my-applications/bin/1.sh: line 48: sensors: command not found
/root/my-applications/bin/1.sh: line 45: acpi: command not found
/root/my-applications/bin/1.sh: line 45: acpi: command not found
/bin/lsb_release: line 8: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8): No such file or directory
#
Results
Results
YAD Test.jpg (26.42 KiB) Viewed 828 times
Clarity
Posts: 3888
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1643 times
Been thanked: 528 times

Re: Script failures - User Error copy from source <SOLVED>

Post by Clarity »

BTW: This little utility is small and fast. Quick useful utility to complement current system contents.

I am trying to become a little proficient with some understanding in use of YAD. I've been away from coding for so long, I cannot remember any at this point ... except maybe assembler :lol:

User avatar
MochiMoppel
Posts: 1243
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 444 times

Re: Script failures - User Error copy from source <SOLVED>

Post by MochiMoppel »

Clarity wrote: Fri Mar 01, 2024 6:32 am

I made my copy via a cut-paste directly from the webpage into Geany on my BKWP64 v10.0.5

And? Did it work this time? What is different from your first failed attempt? I still don't understand how you managed to infest the code with extra spaces. Unless you examine the cause you might fall into the same trap next time.

I copied your version from this thread and ran an immediate test of your version. Results

Code: Select all

YADtest-sysinfo.sh
/root/my-applications/bin/1.sh: line 48: sensors: command not found
/root/my-applications/bin/1.sh: line 45: acpi: command not found
/root/my-applications/bin/1.sh: line 45: acpi: command not found
/bin/lsb_release: line 8: warning: setlocale: LC_ALL: cannot change locale (C.UTF-8): No such file or directory
#

YAD Test.jpg

Not a surprise. I'm also using BW64 v10.0.5 and I already told you that it works. Disregard the error messages, they are not syntax related.

Clarity
Posts: 3888
Joined: Fri Jul 24, 2020 10:59 pm
Has thanked: 1643 times
Been thanked: 528 times

Re: Script failures - User Error copy from source <SOLVED>

Post by Clarity »

I'm using the latest Chrome browser.

In looking at the site's screens I can see that somehow my cut-paste attempting something I would NOT have expected. Especially after repeated attempts. I also coded a little utiltiy that attempted to remove the first column up to and including the intreger without disturbing the remainder of the line.

With your help, I was able to narrow down that I SHOULD have done a side by side comparison without ASSUMING the cut-paste was accurate.

Thus, the user (ME) introduced errors and did not verify the copy-from file against the flie set up for execution.

Thanks AGAIN, @MochiMoppel. Swell of you to guide me.

Post Reply

Return to “Scripts”