Skip to main content
Topic: YAD (Read 465 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

YAD

Hello Guys,

I am trying to create a simple dialog to clear the cache.

I have created a script with following contents>

Code: [Select]
#! /bin/bash

yad --title "RAMFLUSH" --image=/home/tokaro/artwork/images/icons8-ram-94.png

sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"


My question is

How can I check whether the dialog executed successfully (echo $? works in terminal, but how to check if gui executed with success ?)

How can I use/call a command which requires SU privileges in script aimed to be run as regular user?

As written above.

Thank you!




Re: YAD

Reply #2
Hi,

thank you for the reply, but this is no solution for my issue.
My conditions are:

I use XFCE
I  made the script and set as executable> chmod +x ramFlush.sh.Then i have created a launcher in bottom panel, and added following to sudoers file >

tokaro ALL=(ALL) NOPASSWD: /home/tokaro/ramFlush.sh

So when I click the OK button it disappears.

So how I can check that the button did what was intended and cleared the cache? When I press the OK button and instantly echo $? in terminal?

Thanks

Re: YAD

Reply #3
Exit status is a number indicating if a command ran successfully (0) or encountered an error (non-zero).

you can grab this exit status code and do whatever you want with it.
you can print a massage in terminal if it's 0. (example in link provided by artoo)
you can print it in any notification software.
you can save it to a log file.
you can print it in a dialog box.

as a raw outpur (0, 1) or interpenetrated as a text massage (YAD executed successfully.)

Re: YAD

Reply #4
Thank you for the hint.

So I did minor change to the script with following contents>
Code: [Select]
#! /bin/bash

yad --title "RAMFLUSH" --image=/home/tokaro/artwork/images/icons8-ram-94.png
sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"

eval $@

if [ $? -eq 0 ];
then
    yad --info --text "$CMD executed successfully"
else
    yad --info --text "$CMD terminated unsuccessfully"
fi

So now it displays in a new dialog with the message "executed successfully".

Is there any other way to use a command which requires root privileges in script run as regular user except the version with sudo I use?

How would you pass the exit code to notification app?

Thanks


Re: YAD

Reply #5
make udev rule or a cron job to give read and write access to user when system starts you can run following command in rule or job
Code: [Select]
/bin/chmod g+w /proc/sys/vm/drop_caches

or add the command that needed to be run with sudo to sudoers with "NOPASSWD"
Code: [Select]
%wheel ALL=(ALL:ALL) NOPASSWD: sudo sh -c "echo 3 > /proc/sys/vm/drop_caches"

It would be better to ask such questions in stack exchange,  and most likely someone already faced same problem as you, just do a search there, here

https://unix.stackexchange.com/questions/18830/how-to-run-a-specific-program-as-root-without-a-password-prompt