Capture YAD combobox output as variable..?

interpretive language scripts


Moderator: Forum moderators

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Capture YAD combobox output as variable..?

Post by mikewalsh »

Hiya, gang.

Quite a simple one for many of you, I guess - most could probably do this in their sleep! - but it's still near the start of my scripting journey for me.

As the title says, I would like to know the simplest way to assign the output from a YAD combobox to a set variable? In this case, a list of eight different primary drive partitions (sda1 through to sdh1), which I would like, in every case, to assign to the same variable....for later inclusion in another line of code.

Code: Select all

yad --form --field="Partition:CB" sda1\!sdb1\!sdc1\!sdd1\!sde1\!sdf1\!sdg1\!sdh1

Run from the terminal, whatever is selected when the 'OK' button is clicked-on returns

Code: Select all

sdx1|

......where x=anything from a → h. What I would then like to do is to assign this output - whatever it is - to the same variable each time.....probably "DRIVEPART".

Is there a simple way to do this, or is it inextricably bound-up with sed, awk, cut & all that stuff? 'Cos if I've got to find the time to learn all that, it's going to be years before I get anywhere near what I want to achieve; I don't have half as much time to play around with all this stuff as I used to....

(I've always been crap at learning languages..! :D For me, it's an uphill struggle....)

Any advice, comments, examples, etc, will be appreciated.....as ever.

Mike. ;)

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

Hey Mike!
I would do it something like this (using cut to get the partition without the "|"):

Code: Select all

PARTS=$(yad --form --field="Partition:CB" sda1\!sdb1\!sdc1\!sdd1\!sde1\!sdf1\!sdg1\!sdh1)
DRIVEPART="`echo $PARTS | cut -d "|" -f 1`"
echo $DRIVEPART

Also, you can scan first for all existing partitions ($devs variable), then:

Code: Select all

devs="$(blkid -o list | grep /dev | sort | cut -d" " -f1 | grep -E -v "/loop|sr0|swap" | sed "s|/dev/||g" | tr '\n' '!')"
echo $devs
PARTS=$(yad --form --field="Partition:CB" $devs)
DRIVEPART="`echo $PARTS | cut -d "|" -f 1`"
echo $DRIVEPART

Fred

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

@fredx181 :-

Hi, Fred.

Uh.....o-kayyy. Question; how would I use that first code block to get the --field to show up in a GUI? You've lost me..!

I'm attempting a re-write of the DriveSpeed-portable I published earlier. Certain stuff would have to be re-written for a .pet anyway; the portable relies on being physically moved to the location where it will be used; a .pet package, being 'static', would have to choose partitions manually before running the script.

This is what I have so far:-

Code: Select all

#!/bin/sh
#
# GUI to run DriveSpeed functions - © Mike Walsh May 2021 : GNU All-permissive licence applies
#
HERE="$(dirname "$(readlink -f "$0")")"
ICONS=/usr/share/pixmaps/DS-ICONS
#
yad --center --window-icon="$ICONS/drivespeed-icon.png" --title="     DriveSpeed! - Basic drive speed tester    " --form --width=380 --text="                Choose your partition to test.
    Select block size, and file size. THEN: first
    run the write test, followed by the read
  test. REMEMBER - clear drive cache buffers
   between runs for optimum performance." \
--image="/$ICONS/drivespeed.png" \

What I would THEN like after this would be:

--field (combobox to choose partition) - sda1:sdb1:sdc1:sdd1:sde1:sdf1:sdg1:sdh1 - set as a variable (DRIVEPART)
--field (combobox to select block size) - 256k:512k:1M:4M - set as a variable (BLOCKSIZE)
--field (combobox to select file size) - 1GB:2GB:4GB - set as a variable (FILESIZE)

Which I can then 'drop into', and:-

Run the 'write' test
Run the 'read' test

Followed by the bottom lines, consisting of:-

Buttons for "Clear buffers" "About/Credits" "Help" "Quit" (this line as it is currently in the 'portable')

Umm.....make sense? Or am I attempting to "bite off" more than I can presently chew..?? :roll: Be honest with me!

Mike. ;)

User avatar
rockedge
Site Admin
Posts: 6545
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2749 times
Been thanked: 2625 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by rockedge »

@mikewalsh I added Fred's code to yours

Code: Select all

#!/bin/sh
#
# GUI to run DriveSpeed functions - © Mike Walsh May 2021 : GNU All-permissive licence applies
#
HERE="$(dirname "$(readlink -f "$0")")"
ICONS=/usr/share/pixmaps/DS-ICONS

# piece from fredx181 mixed in.

devs="$(blkid -o list | grep /dev | sort | cut -d" " -f1 | grep -E -v "/loop|sr0|swap" | sed "s|/dev/||g" | tr '\n' '!')"
echo $devs
yad --center --window-icon="$ICONS/drivespeed-icon.png" --title="DriveSpeed! - Basic drive speed tester    " --form --width=380 --text="Choose your partition to test.
    Select block size, and file size. THEN: first
    run the write test, followed by the read
    test. REMEMBER - clear drive cache buffers
    between runs for optimum performance." \
--image="/$ICONS/drivespeed.png" \
--field="Partition:CB" $devs

DRIVEPART="`echo $PARTS | cut -d "|" -f 1`"
echo $DRIVEPART
User avatar
MochiMoppel
Posts: 1236
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 21 times
Been thanked: 439 times

Re: Capture YAD combobox output as variable..?

Post by MochiMoppel »

fredx181 wrote: Mon May 03, 2021 10:10 pm

I would do it something like this (using cut to get the partition without the "|"):

Code: Select all

PARTS=$(yad --form --field="Partition:CB" sda1\!sdb1\!sdc1\!sdd1\!sde1\!sdf1\!sdg1\!sdh1)
DRIVEPART="`echo $PARTS | cut -d "|" -f 1`"
echo $DRIVEPART

If it's OK to change the yad statement I would cut the cut:

Code: Select all

DRIVEPART=$(yad --form --separator="" --field="Partition:CB" sda1\!sdb1\!sdc1\!sdd1\!sde1\!sdf1\!sdg1\!sdh1)
echo $DRIVEPART
User avatar
rockedge
Site Admin
Posts: 6545
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2749 times
Been thanked: 2625 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by rockedge »

modified :

Code: Select all

#!/bin/sh
#
# GUI to run DriveSpeed functions - © Mike Walsh May 2021 : GNU All-permissive licence applies
#
HERE="$(dirname "$(readlink -f "$0")")"
ICONS=/usr/share/pixmaps/DS-ICONS

# piece from fredx181 modified by MochiMoppel mixed in.

devs="$(blkid -o list | grep /dev | sort | cut -d" " -f1 | grep -E -v "/loop|sr0|swap" | sed "s|/dev/||g" | tr '\n' '!')"
echo $devs
DRIVEPART=$(yad --center --window-icon="$ICONS/drivespeed-icon.png" --title="DriveSpeed! - Basic drive speed tester    " --form --width=380 --text="Choose your partition to test.
    Select block size, and file size. THEN: first
    run the write test, followed by the read
    test. REMEMBER - clear drive cache buffers
    between runs for optimum performance." \
--image="/$ICONS/drivespeed.png" \
--separator="" \
--field="Partition:CB" $devs)

echo $DRIVEPART 
User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

I'll have a look at all this tomorrow, guys. It's way past time I was "heading up the wooden hill"..!

I'm sorry to say, so much of this is pure "Greek" to me. I hold my hand up; this is where my lack of Bash experience shows through, I'm afraid. I'm still at the "bread & butter" stage.....basic file-manipulation, if-then-else conditional statements, etc. The "meat & potatoes" of scripting - sed, awk, grep, cut, etc, I haven't even begun to get to grips with yet.....and it shows, doesn't it?

I don't have a clue what that stuff of Fred's (or Mochi's) means, or even does. Embarrassing, isn't it? :oops: On top of which, I now don't have half as much time to devote to learning this stuff like I used to.....

(*sigh...*)

Ah, well; looks I have bitten off more than I can chew, this time..... Image

Mike. ;)

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

Re: Capture YAD combobox output as variable..?

Post by MochiMoppel »

mikewalsh wrote: Tue May 04, 2021 1:07 am

I don't have a clue what that stuff of Fred's (or Mochi's) means, or even does.

Captures YAD combobox output as a variable ;)

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

Hi Mike,
I saw that you updated already DriveSpeed to v2.
But JUST in case you'd still like to add a partition chooser, here's how I'd do it (really not that complicated)
In the DriveSpeed script, just before the existing yad command block, add:

Code: Select all

devs="$(blkid -o list | grep /dev | sort | cut -d" " -f1 | grep -E -v "/loop|sr0|swap" | sed "s|/dev/||g" | tr '\n' '!')"
echo $devs
PARTS=$(yad --center --form --field="Partition:CB" $devs)
[ $? -ne 0 ] && exit
export DRIVEPART="`echo $PARTS | cut -d "|" -f 1`"

So then the partition chooser runs first, and after that your drivespeed GUI.

Then in all read* and write* scripts in DATA, just before the rxvt command line, add:

Code: Select all

#HERE="$(dirname "$(readlink -f "$0")")"
HERE="/mnt/$DRIVEPART"
mkdir -p "$HERE"
mount /dev/$DRIVEPART "$HERE" 2> /dev/null

As you can see, the "HERE" variable is replaced by /mnt/$DRIVEPART (DRIVEPART variable from running earlier the yad partition chooser)

Fred

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Capture YAD combobox output as variable..?

Post by stemsee »

Here is another option, a bit simpler I think.

Code: Select all

DRIVEPART=$(fdisk -l | grep "/dev/" | grep -v Disk | tr '\n' '#' | yad --center --form --item-separator='#' --field="Partition:CB" | cut -f1 -d' ')
HERE="/mnt/$(echo $DRIVEPART | cut -d'/' -f3)"
mount $DRIVEPART "$HERE" 2> /dev/null
User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

@fredx181 :-

A-ha! So, it's supposed to do that, is it? I couldn't quite work out why the partition chooser came up first, all on its own.....then clearing it would bring up the GUI.

Would it be too hard to build this function actually into the GUI itself? I appreciate all the suggestions you guys have come up with, really I do; God knows, I'm definitely out of my depth with the code itself. And I've never been one to disregard, or refuse to acknowledge the assistance of others; several of my other "projects" have definitely been enhanced by community input, I'll be the first to admit.

Credit where credit is due, and all that. We don't all have the same abilities, or strengths, so.....we do what we can, for the good of all. (Well, that's MY excuse, anyway.....an' I'm sticking to it..!) :lol: :shock: :D

Mike. ;)

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Capture YAD combobox output as variable..?

Post by stemsee »

A one liner! I didn't read your script, so maybe not suitable! But it was a good exercise!

You can type in the desired mount directory ... e.g. sda8 ... it will be created in /mnt

edit: added unmount function.

Code: Select all

yad --center --form --item-separator='#' --field="Mount:FBTN" "bash -c \"mkdir -p /mnt/"%3"; mount "%2" /mnt/"%3" \"" --field="Partition:CBE" "`fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | tr '\n' '#'`" --field="Mount Dir:CBE" `ls /mnt/ | tr '\n' '#'` --field="unmount:FBTN" "bash -c \"umount -f -A "%2"; umount -f -A "%3" \"" --no-buttons --title="Partition Mounter" &
User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

stemsee wrote: Wed May 05, 2021 12:42 am

A one liner! I didn't read your script, so maybe not suitable! But it was a good exercise!

You can type in the desired mount directory ... e.g. sda8 ... it will be created in /mnt

edit: added unmount function.

Code: Select all

yad --center --form --item-separator='#' --field="Mount:FBTN" "bash -c \"mkdir -p /mnt/"%3"; mount "%2" /mnt/"%3" \"" --field="Partition:CBE" "`fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | tr '\n' '#'`" --field="Mount Dir:CBE" `ls /mnt/ | tr '\n' '#'` --field="unmount:FBTN" "bash -c \"umount -f -A "%2"; umount -f -A "%3" \"" --no-buttons --title="Partition Mounter" &

@stemsee :-

Well, thanks for that! I'll take a look at it tomorrow, when I'm back in the 'land of the living'....

'Night, all.

Mike. ;)

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Capture YAD combobox output as variable..?

Post by stemsee »

ok.....here is a template with more fields and buttons as you mentioned.

Code: Select all

#!/bin/sh
function testa (){
	echo "$1 $2 $3"
}; export -f testa
function testb (){
	echo "$1 $2 $3"
}; export -f testb

yad --center \
--form --item-separator='#' \
--field="Mount:FBTN" "bash -c \"mkdir -p /mnt/"%3"; mount "%2" /mnt/"%3" \"" \
--field="Partition:CBE" "`fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | tr '\n' '#'`" \
--field="Mount Dir:CBE" `ls /mnt/ | tr '\n' '#'` \
--field="unmount:FBTN" "bash -c \"umount -f -A "%2"; umount -f -A "%3" \"" \
--field="bytesize:CBE" "64#128#256#512#1024#" \
--field="test:CBE" "write#read#" \
--field="file size in M:CBE" "32#64#128#256#512#1024#2048#4096#" \
--field="Run TestA:FBTN" "bash -c \"testa %5 %6 %7 \"" \
--field="Run Testb:FBTN" "bash -c \"testb %5 %6 %7 \"" \
--no-buttons \
--title="Partition Mounter" &
example.png
example.png (18.65 KiB) Viewed 1957 times

:

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

mikewalsh wrote:

Would it be too hard to build this function actually into the GUI itself?

Yes, adding partition chooser would be more complicated, but luckily we had stemsee's input :thumbup2:
Here's what I got so far, it can replace your "DriveSpeed!" script, the dd output is showing on a yad --text-info GUI (so not using your read/write scripts in DATA):

Code: Select all

#!/bin/sh

export LANG=C

HERE="$(dirname "$(readlink -f "$0")")"

function runtest () {

ddwrite () {
[ -f $PARTMNT/testfile ] && rm -f $PARTMNT/testfile
dd if=/dev/zero of=$PARTMNT/testfile bs=$BTSIZE status=progress oflag=sync count=$FLSIZE 2>&1 | yad --center --title="~ Drive write speed $PARTMNT - $BTSIZE block....." --text-info --tail --width 650 --height 50 --button=Close/Cancel
}

ddread () {
dd if=$PARTMNT/testfile of=/dev/null bs=$BTSIZE status=progress oflag=sync 2>&1 | yad --center --title="~ Drive read speed  $PARTMNT - $BTSIZE block....." --text-info --tail --width 650 --height 50 --button=Close/Cancel
}

echo "$1 $2 $3"
export PARTMNT=/mnt/$3
echo /mnt/$3/testfile > /tmp/dd_testfile
if [ $1 = write ]; then
[ $2 = 256k ] && export BTSIZE=$2 && export FLSIZE=4096
[ $2 = 512k ] && export BTSIZE=$2 && export FLSIZE=2048
[ $2 = 1M ] && export BTSIZE=$2 && export FLSIZE=1024
ddwrite
fi
if [ $1 = read ]; then
[ ! -f $PARTMNT/testfile ] && yad --center --borders=10 --title="Please run write first" --text="Please run one of the 'write' options first" --button="Close:0" && exit
[ $2 = 256k ] && export BTSIZE=$2
[ $2 = 512k ] && export BTSIZE=$2
[ $2 = 1M ] && export BTSIZE=$2
ddread
fi

}; export -f runtest

yad --center --window-icon="$HERE/DATA/ICONS/drivespeed-icon.png" --title="     DriveSpeed! - Basic drive speed tester - v2    " --form --width=480 --text="           Select block size of your choice. Run write operation
     first, THEN the read operation. DON'T FORGET: clear buffers 
           in between; this helps to keep each operation 'clean'.       " \
--image="$HERE/DATA/ICONS/drivespeed.png" \
--form --item-separator='#' --columns=3 \
--field="     Partition:":lbl "" \
--field="Write 256k":fbtn "bash -c \"runtest write 256k %4 \"" \
--field="Read 256k":fbtn "bash -c \"runtest read 256k %4 \"" \
--field=":CB" "`fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | sed 's|/dev/||g' | tr '\n' '#'`" \
--field="Write 512k":fbtn "bash -c \"runtest write 512k %4 \"" \
--field="Read 512K":fbtn "bash -c \"runtest read 512k %4 \"" \
--field="Mount:FBTN" "bash -c \"mkdir -p /mnt/"%4"; mount /dev/"%4" /mnt/"%4" \"" \
--field="Write 1Mb":fbtn "bash -c \"runtest write 1M %4 \"" \
--field="Read 1Mb":fbtn "bash -c \"runtest read 1M %4 \"" \
--button="CLEAR BUFFERS":$HERE/DATA/clear_cache --button="About/Credits":$HERE/DATA/dsabout --button="HELP":$HERE/DATA/info.sh --button="QUIT#$HERE/DATA/ICONS/cancel-icon.png":1 --buttons-layout=center
rm -f $(cat /tmp/dd_testfile)

The yad --text-info way is probably using more CPU than your original way of output through rxvt, tell me if you prefer the rxvt output and we can change it again.
I've made last line to remove the testfile (which is needed IMO when exiting the script)

DriveSpeed!
DriveSpeed!
2021-05-05-203143_557x274_scrot.png (70.76 KiB) Viewed 1944 times
2021-05-05-220207_652x146_scrot.png
2021-05-05-220207_652x146_scrot.png (19.47 KiB) Viewed 1933 times
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Capture YAD combobox output as variable..?

Post by stemsee »

just a suggestion of using notebok paned form and info, and a pipe to send data to the info pane. But then you couldnt have all test info boxes open at the same time .... or could you?? why not accumulate the test data in the info pane?

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

@fredx181 :-

Mmm.....sweet! Almost exactly what I had in mind, mate. "Frederico strikes again..." :D

I was planning on adding a final line to auto-remove the testfile at the end of the script myself. That, too, works nicely; cheers for that.

I see what you've done with the readout window. This is very similar to the way Zigbert did the "progress" window for pBurn, isn't it? I was originally in 2 minds about using this, or returning to the rxvt terminal window, but.....I think this is probably better. It's easier to review the operation, line by line, should the user wish to.

The good thing about having added the partition selector, and re-jigged it the way you have is twofold. Despite being a 'portable', you can put it where you want - like the many other 'portables' - but you can then choose your partition, and run all the tests from wherever it's located. It no longer relies on being physically 'moved' from drive to drive to do its job...

That same thing means it's easier to turn into a .pet, too. So, this can then be offered in both .pet AND 'portable'.....those who want a Menu entry to launch it can also be accommodated.

I've made one modification; altered the dimensions for the progress window, from 650x50 to 800x300. I don't suppose I'm unique in this; I run with a fairly large global fontsize - 18px to 20 px on average. Reasons for this are various; my screen is between 3 & 4 feet away from me, and my eyesight is getting worse as I get older (and cataracts developing don't help!) For me, at least, the actual progress window was too small to even display a single line of text!

Aside from that, very neat work as always, Fred. This is becoming a habit, isn't it? I come up with an idea and a basic layout, and you end up supplying most of the code! :oops: Never mind; community input usually helps to hone and improve upon early releases of anything, and the idea has always been for this to be a community tool that everyone can use. So, no worries; the assistance of your good self, and others, is as always highly appreciated.

Cheers!

I'll need to do a re-write of the info panel, and the About/Credits box needs some additional credits adding now, so.....I'll get on with those, and re-pack it as a .pet as well this time.

Stay tuned.

Mike. ;) :thumbup:

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

I'm glad it's useful for you Mike!
Credit should also go to @stemsee for the pointer about adding the partition choice to the GUI, to be honest I couldn't remember how to do it.

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

fredx181 wrote: Wed May 05, 2021 10:04 pm

I'm glad it's useful for you Mike!
Credit should also go to @stemsee for the pointer about adding the partition choice to the GUI, to be honest I couldn't remember how to do it.

@fredx181 :-

You're both mentioned in the credits, don't worry about that. Credit where its due, mate. :thumbup:

I've just this second finished tiffling about with odd items. I think I've got time to run the packages up before I start yawning..... :lol:

Mike. ;)

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Capture YAD combobox output as variable..?

Post by stemsee »

Thanks for the cred :thumbup2: it!

I combined the test results yad info box and added clear text button! Use it if you like it.

My usb-c drive reads at 4GB/s but writes at 34.1 mb/s

ds.png
ds.png (66.37 KiB) Viewed 1889 times

Code: Select all

#!/bin/sh
#
# GUI to run DriveSpeed functions - © Mike Walsh May 2021 : GNU All-permissive licence applies ~~~~ With thanks to Fredx181, stemsee, and others ~~~~
#
export LANG=C

HERE="$(dirname "$(readlink -f "$0")")"

function runtest () {

ddwrite () {
[ -f $PARTMNT/testfile ] && rm -f $PARTMNT/testfile
echo $BTSIZE block $FLSIZE $PARTMNT
dd if=/dev/zero of=$PARTMNT/testfile bs=$BTSIZE status=progress oflag=sync count=$FLSIZE 2>&1 #| yad --window-icon="$HERE/DATA/ICONS/drivespeed-icon.png" --center --title="~ Drive write speed - $BTSIZE block....." --text-info --tail --width 800 --height 300 --button=Close/Cancel
}

ddread () {
echo $BTSIZE block $PARTMNT
dd if=$PARTMNT/testfile of=/dev/null bs=$BTSIZE status=progress oflag=sync 2>&1 #| yad --window-icon="$HERE/DATA/ICONS/drivespeed-icon.png" --center --title="~ Drive read speed - $BTSIZE block....." --text-info --tail --width 800 --height 300 --button=Close/Cancel
}

echo "$1 $2 $3"
export PARTMNT=/mnt/$3
echo /mnt/$3/testfile > /tmp/dd_testfile
if [ $1 = write ]; then
[ $2 = 256k ] && export BTSIZE=$2 && export FLSIZE=4096
[ $2 = 512k ] && export BTSIZE=$2 && export FLSIZE=2048
[ $2 = 1M ] && export BTSIZE=$2 && export FLSIZE=1024
ddwrite >>/tmp/drivespeed  
fi
if [ $1 = read ]; then
x=1
[ ! -f $PARTMNT/testfile ] && echo "Please run one of the 'write' options first...!" > /tmp/drivespeed && exit
[ $2 = 256k ] && export BTSIZE=$2
[ $2 = 512k ] && export BTSIZE=$2
[ $2 = 1M ] && export BTSIZE=$2
ddread >>/tmp/drivespeed 
fi
}
export -f runtest
echo -e "#!/bin/sh
echo -e '\f' > /tmp/drivespeed

echo -e '\f' > /tmp/drivespeed
" > /tmp/clear.sh
chmod 755 /tmp/clear.sh

[[ -p /tmp/drivespeed ]] && rm -f /tmp/drivespeed
[[ ! -p /tmp/drivespeed ]] && mkfifo -m 755 /tmp/drivespeed
exec 6<> /tmp/drivespeed
yad --plug=$$ --tabnum=1 --form --width=480 --text="                        Select your partition first, and 'mount' it.
            Select block size of your choice. Run write operation
                              first, THEN the read operation. 
             DON'T FORGET: clear buffers in between runs; this 
                           helps to keep each operation 'clean'.       
                                                                                                         " \
--image="$HERE/DATA/ICONS/drivespeed.png" \
--form --item-separator='#' --columns=3 \
--field="MOUNT:FBTN" "bash -c \"mkdir -p /mnt/"%4"; mount /dev/"%4" /mnt/"%4" \"" \
--field="Write 256k":fbtn "bash -c \"runtest write 256k %4 \"" \
--field="Read 256k":fbtn "bash -c \"runtest read 256k %4  \"" \
--field=":CB" "`fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | sed 's|/dev/||g' | tr '\n' '#'`" \
--field="Write 512k":fbtn "bash -c \"runtest write 512k %4  \"" \
--field="Read 512K":fbtn "bash -c \"runtest read 512k %4 \"" \
--field="DisMount:FBTN" "bash -c \"umount -f -A /mnt/"%4" \"" \
--field="Write 1Mb":fbtn "bash -c \"runtest write 1M %4 \"" \
--field="Read 1Mb":fbtn "bash -c \"runtest read 1M %4  \""  &
yad --plug=$$ --tabnum=2 --listen --tail --editable --text-info "" <& 6 &
yad --center --title="     DriveSpeed! - Basic drive speed tester - v3    "  --window-icon="$HERE/DATA/ICONS/drivespeed-icon.png"  --paned --key=$$ --tab=Control --tab=Data --button-layout=center --button="CLEAR BUFFERS":$HERE/DATA/clear_cache --button="STOP TEST":"killall dd"  --button="Clear Data":/tmp/clear.sh --button="About/Credits":"$HERE/DATA/dsabout" --button="HELP":$HERE/DATA/info.sh --button="QUIT!$HERE/DATA/ICONS/cancel-icon.png":1 &
wait $!
rm -f $(cat /tmp/dd_testfile)
User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

@stemsee :-

Mm. Yes, I like it.

I guess this is all going to boil down to one of two things; do you like everything contained within a single window, or do you mind the app spawning pop-up windows as it performs its task?

The addition of the "Stop Test/Clear DATA" buttons should please bigpup, who is somewhat critical of the length of the test, i.e., the size of the 1 GB testfile. I've tried to explain to him that you only get a true, "real-world" reading of your drive's performance towards the end of the test, as the drive's cache buffers fill up & write-speed slows down, but he seems unconvinced!

I'll post the modified script in the DriveSpeed! thread, and let folks try it out for themselves; we'll see what feedback is forthcoming.

Cheers!

Mike. ;)

User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Capture YAD combobox output as variable..?

Post by stemsee »

ATM it is possible to perform all 6 tests simultaneously!

User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

@fredx181 / @stemsee :-

I think we'll run with stemsee's re-write.....v4. Coupla questions, though. Is there a point to having the dis-mount button? For me, at least, it doesn't seem to actually DO anything.....

The other one's simple. How do we center the text in the title bar? (I've never actually attempted that before...)

Are these FatDog peculiarities, stemsee? I see they always center themselves in Grant's YAD guide; I know he uses FatDog. It won't do this in JWM....!

Mike. ;)

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

I'm having the problem with v4 that it doesn't quit properly after stopping the test and clicking the QUIT button, see pic, anyone else having the same ?
EDIT: When I click 'Clear Data" first it quits okay.

2021-05-06-193914_833x418_scrot.png
2021-05-06-193914_833x418_scrot.png (24.89 KiB) Viewed 1875 times
User avatar
mikewalsh
Moderator
Posts: 6163
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 795 times
Been thanked: 1981 times

Re: Capture YAD combobox output as variable..?

Post by mikewalsh »

Same here, Fred. Behaves in exactly the same way; stop test >> Quit, no cigar; stop test >> Clear Data >> Quit, works fine.....

Mike. ;)

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

mikewalsh wrote: Thu May 06, 2021 6:35 pm

Same here, Fred. Behaves in exactly the same way; stop test >> Quit, no cigar; stop test >> Clear Data >> Quit, works fine.....

Mike. ;)

Aha, that's bad, @stemsee or anyone, you have any idea how to fix this, I tried but couldn't.

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

mikewalsh wrote:

I think we'll run with stemsee's re-write.....v4. Coupla questions, though. Is there a point to having the dis-mount button? For me, at least, it doesn't seem to actually DO anything.....

For me the DisMount works, is it useful ?... not for me really.

The other one's simple. How do we center the text in the title bar? (I've never actually attempted that before...)

I think that's a Jwm vs Openbox issue, I use Openbox and the title centers automatically (not on Jwm AFAIK).

Fred

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

I think we forgot about a very important thing:
What if the user doesn't mount the partition, then it could be that the testfile will be created in just an empty folder on the system (e.g. /mnt/sdb1).
So the test result will be false.
Therefore, better check first if the directory is really a mountpoint, so in the function runtest:

Code: Select all

echo "$1 $2 $3"
export PARTMNT=/mnt/$3
if mountpoint -q $PARTMNT; then
echo OK
else
yad --center --width=400 --borders=10 --window-icon="$HERE/DATA/ICONS/drivespeed-icon.png" --title="Not mounted...." --text="Please mount $3 first...!" --button="Close:0" && exit
fi

Fred

User avatar
fredx181
Posts: 3074
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 374 times
Been thanked: 1310 times
Contact:

Re: Capture YAD combobox output as variable..?

Post by fredx181 »

v4 fixed and improved:
- When click "Stop Test" the data will be cleared (same as when clicking Clr Data), so it will quit OK now when clicking QUIT.
- Will display ok also when using yad gtk3 version.
- Checks if directory is really a mount point (e.g. /mnt/sda2)

Fred

DriveSpeed-v4-fixed.tar.gz
(1.56 KiB) Downloaded 66 times
User avatar
stemsee
Posts: 779
Joined: Sun Jul 26, 2020 8:11 am
Location: lattitude 8
Has thanked: 185 times
Been thanked: 131 times

Re: Capture YAD combobox output as variable..?

Post by stemsee »

Hi fred

I think it is not necesssary to spawn a new instance of yad ... just send to pipe!

Code: Select all

export PARTMNT=/mnt/$3
if mountpoint -q $PARTMNT; then
echo OK
else
echo -e "$3 is Not mounted....\nPlease mount $3 first...!" >> /tmp/drivespeed  && exit
fi
v4.png
v4.png (40.67 KiB) Viewed 1793 times

Also when stopping the test and clearing the data info then I feel that I normally like to scrutinize the data. So now I must watch the test as it happens and process it in real time. Personally I prefer to review it after stopping and clear manually. Maybe the quit button could do the clearing first, before actually quitting, instead of stop test. Maybe a trap function also to clear /tmp/clear.sh ...

Another problem is that all tests can be run concurrently on the same partition, giving read and write results. Maybe using flags in /tmp can prevent concurrency?

stemsee

Post Reply

Return to “Scripts”