Bash script issue - not displaying onscreen [SOLVED]

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Hello everyone,

I am trying to make a conky net bandwidth speed widget.

Here is the conky:

Code: Select all

conky.config = {
-- — Conky settings

	background = false,
	total_run_times = 1,
	no_buffers = true,	

-- — Window specifications with Background

	own_window = true,
	own_window_type = dock,
    own_window_hints = 'skip_taskbar,skip_pager,undecorated,above',
    own_window_transparent = false,
	own_window_argb_visual = true,
	own_window_argb_value = 0,
	own_window_colour = '000000', 
	
	double_buffer = true,
	minimum_width = 300, minimum_height = 263,
	alignment = 'middle_middle',
	
	gap_x = 20,
	gap_y = 20,
};

conky.text = [[
${execp ./speed.sh}
]];
Here is the bash script:

Code: Select all

#!/bin/bash

# Define your functions
function first_function {
    echo "First function is running..."
    if command -v speedtest-cli >/dev/null 2>&1; then
        speedtest-cli > ~/Desktop/speed.tmp
        if [ $? -eq 0 ]; then
            echo "Speedtest completed successfully and file created."
        else
            echo "Speedtest failed to run."
        fi
    else
        echo "speedtest-cli is not installed or not in PATH."
        exit 1
    fi
    echo "First function is done."
}

function second_function {
    echo "Second function is running..."
    if [ -f ~/Desktop/speed.tmp ]; then
        down=$(cat  ~/Desktop/speed.tmp | grep "Download:" | awk '{print $2}')
        echo "Download speed extracted: $down"
    else
        echo "Speedtest result file not found."
        exit 1
    fi
    echo "Second function is done."
}

function third_function {
    echo "Third function is running..."
    echo "\${goto 35}\${voffset 15}\${color red}Download Spd: $down"
    echo "Third function is done."
}

function fourth_function {
    echo "Fourth function is running..."
    mpg123 /home/logansfury/Music/effects/ta-daa.mp3
    echo "Fourth function is done."
}

# Call your functions in sequence
first_function
second_function
third_function
fourth_function
When launched in terminal, it does everything and echoes the download speed from the .tmp file. However when launched with the conky play button, nothing happens. I never hear the .mp3, I never see any text onscreen.

Can anyone help fix please?

Thank you for reading,

Logan
Last edited by Logansfury on Fri May 31, 2024 7:44 am, edited 1 time in total.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 8
Level 8
Posts: 2080
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script issue - not displaying onscreen

Post by Koentje »

This works for me..
bandwidth.tar.gz
(1.04 KiB) Downloaded 22 times
Image
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen

Post by Logansfury »

Koentje wrote: Fri May 31, 2024 7:31 am This works for me..

bandwidth.tar.gz
Downloading and testing now, thank you very much :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen

Post by Logansfury »

working perfectly! The fourth function isn't playing the alert noise but that was just for testing purposes anyway.

I have taken out the echoes that were printing on screen, replaced with sleep 0.5 and added a a line to grep the Upload speed as well.

Thank you so much!
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

my sound was turned down, the script is playing the sound.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Oh yes :D

The script survived my edits! I now have it displaying up and down and the speed per seconds:

Code: Select all

#!/bin/bash

# Define your functions
function first_function {
    if command -v speedtest-cli >/dev/null 2>&1; then
        speedtest-cli > ./speed.tmp
        if [ $? -eq 0 ]; then
            sleep 0.5
        else
            echo "Speedtest failed to run."
        fi
    else
        echo "speedtest-cli is not installed or not in PATH."
        exit 1
    fi
}

function second_function {
    if [ -f ./speed.tmp ]; then
        down=$(cat  ./speed.tmp | grep "Download:" | awk '{print $2 $3}')
        up=$(cat  ./speed.tmp | grep "Upload:" | awk '{print $2 $3}')
    else
        echo "Speedtest result file not found."
        exit 1
    fi
}

function third_function {
    echo "\${goto 35}\${voffset 15}\${color red}Download Spd: $down"
    echo "\${goto 35}\${voffset 15}\${color red}Upload Spd: $up"
}

function fourth_function {
    gst-launch-1.0 -q playbin uri=file:///usr/share/mint-artwork/sounds/map.oga
}

# Call your functions in sequence
first_function
second_function
third_function
fourth_function
Now I can do away with the 4th function completely and set a longer interval.

Question: When the conky update interval is set to 5, and an execi 60 exists, which takes precedent? This is setting two different refresh rates isnt it?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 8
Level 8
Posts: 2080
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Koentje »

The refresh rate of the conky is 5 seconds. But the execpi is set to 60 seconds, so it only executes this command every 60 seconds.
Image
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Koentje wrote: Fri May 31, 2024 8:25 am The refresh rate of the conky is 5 seconds. But the execpi is set to 60 seconds, so it only executes this command every 60 seconds.
Far out thank you for confirming that. I will prob readjust to every 5 mins or longer.

my onscreen display is showing 492.97 Mbit/s but Ookla says different:

Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

I just googled "ookla speedtest terminal" and got this page:

https://www.speedtest.net/apps/cli

It says:

Code: Select all

## If migrating from prior bintray install instructions please first...
# sudo rm /etc/apt/sources.list.d/speedtest.list
# sudo apt-get update
# sudo apt-get remove speedtest
## Other non-official binaries will conflict with Speedtest CLI
# Example how to remove using apt-get
# sudo apt-get remove speedtest-cli
$ sudo apt-get install curl
$ curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
$ sudo apt-get install speedtest
So this gets rid of the speedtest-cli that I am using now in favor of Ookla's own cli?

I think I will boot one of my win machines to flashdrive linux instance and remove the speedtest from that and install and test this!
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Oh for crying out loud in an escalated tone of voice......

What is this crap? Running default 21.3 Cinn off the installer flashdrive. Speedtest-cli isn't installed by default so no conflict, but Ookla's speedtest wont install either???

Code: Select all

See "man sudo_root" for details.

mint@mint:~$ speedtest-cli
Command 'speedtest-cli' not found, but can be installed with:
sudo apt install speedtest-cli
mint@mint:~$ sudo apt-get install curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
curl is already the newest version (7.81.0-1ubuntu1.15).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
mint@mint:~$ curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
Detected operating system as LinuxMint/virginia.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Detected apt version as 2.4.11
Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/ookla_speedtest-cli.list...done.
Importing packagecloud gpg key... Packagecloud gpg key imported to /etc/apt/keyrings/ookla_speedtest-cli-archive-keyring.gpg
done.
Running apt-get update... done.

The repository is setup! You can now install packages.
mint@mint:~$ sudo apt-get install speedtest
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package speedtest
mint@mint:~$ 
Anyone have any suggestions that dont involve a ball-peen hammer?
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

I have the script edits complete as far as function, I just need to edit fonts to fit into existing conkys.

I am now displaying downspd Mbit/s / Mbyte/s and upload Mbit/s / Mbyte/s. It seems to be working fine, I think I did clean edits:

Code: Select all

#!/bin/bash

# Define your functions
function first_function {
    if command -v speedtest-cli >/dev/null 2>&1; then
        speedtest-cli > ./speed.tmp
        speedtest-cli --bytes >> ./speed.tmp
        if [ $? -eq 0 ]; then
            sleep 0.5
        else
            echo "\${goto 115}\${color white}\${voffset -12}Speedtest failed to run"
        fi
    else
        echo "speedtest-cli is not installed or not in PATH."
        exit 1
    fi
}

function second_function {
    if [ -f ./speed.tmp ]; then
        down=$(cat ./speed.tmp | grep -E "Download: .*Mbit/s" | awk '{print $2" "$3}')
        bytes_dwn=$(cat ./speed.tmp | grep -E "Download: .*Mbyte/s" | awk '{print $2" "$3}')
        up=$(cat  ./speed.tmp | grep -E "Upload: .*Mbit/s" | awk '{print $2" "$3}')
        bytes_up=$(cat  ./speed.tmp | grep -E "Upload: .*Mbyte/s" | awk '{print $2" "$3}')
    else
        echo "Speedtest result file not found."
        exit 1
    fi
}

function third_function {
    echo "\${goto 95}\${color red}Speed Test"
    echo "\${goto 35}\${color red}Download Spd: \${color white}$down\${color red}/\${color white}$bytes_dwn"
    echo "\${goto 35}\${color red}Upload Spd: \${color white}$up\${color red}/\${color white}$bytes_up"
}

function fourth_function {
    gst-launch-1.0 -q playbin uri=file:///usr/share/mint-artwork/sounds/map.oga
}

# Call your functions in sequence
first_function
second_function
third_function
fourth_function
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Im off to a great start Koentje!

Check it out :)

Image

Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 8
Level 8
Posts: 2080
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Koentje »

You got great speeds over there!
Mines are poor in comparison..

Code: Select all

Download: 76.33 Mbit/s
Upload: 20.08 Mbit/s
Image
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

I have settled on a final look:

Image

This little widget is awesome!!

Thank you Koentje :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Koentje wrote: Fri May 31, 2024 12:33 pm You got great speeds over there!
Mines are poor in comparison..

Code: Select all

Download: 76.33 Mbit/s
Upload: 20.08 Mbit/s
My ISP is the largest cable service provider in the nation and is going fiber-optic cable state by state. I'm still on a coaxial cable coming out the wall to my modem and 1Gig plans are still avail. When they get to my state with the fiber-optics I don't even know how high the connectivity is going to go.

Did you see my post above with the final layout picture? What do you think? :)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Actually I noticed a few things I wanna tweak aesthetically.

Stand by....
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

OK just a few tiny perfecting tweaks. The needle guages are no longer slightly overlapping one another, and I put spaces between the categories and the colons to format the values more cleanly.

NOW I'm done :)

Image
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

NOW I'm done :)
Oh for craps sake no I'm not.

I forgot to put in the update time >.<
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Koentje
Level 8
Level 8
Posts: 2080
Joined: Tue Jan 04, 2022 6:23 pm
Location: Netherlands

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Koentje »

May i ask what you pay for this monthly?
Image
User avatar
Logansfury
Level 8
Level 8
Posts: 2377
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Bash script issue - not displaying onscreen [SOLVED]

Post by Logansfury »

Koentje wrote: Fri May 31, 2024 2:12 pm May i ask what you pay for this monthly?
certainly!

When I was on the 500MB plan I was paying $80.00/month. When I upgraded to 1Gig monthly charge became $124.00
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”