LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Not able to open the gnome-terminal through bash script on hot plug event. (https://www.linuxquestions.org/questions/programming-9/not-able-to-open-the-gnome-terminal-through-bash-script-on-hot-plug-event-4175463606/)

rohaanembedded 05-27-2013 08:46 AM

Not able to open the gnome-terminal through bash script on hot plug event.
 
Dear everyone,

sir i am able to catch the hot plug event of USB device through udev .rule. Even i am able to run ma bigger code with the help of bash scripting only on the event.
but as i am interested in executing the my interactive code on new terminal. so i tried so much to open terminal with "gnome-terminal" command through script.
but its not working fine with udev .rule file, its not opening the terminal on hot plug event. if i ran the script indpendently like ./d.sh to open terminal through this script, everythng goes fine.
seriously need the help Now plzZZZ

for more understanding,

mY udev rules is which call a script run.sh
Quote:

on hot plug run_code.sh is executed
Code:

# Cypress USB vendor ID = 0x0d85
KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="add", ATTR{idVendor}=="0d85", MODE="666", TAG="cyusb_dev", RUN+="/usr/bin/run_code.sh A"
KERNEL=="*", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", ACTION=="remove", TAG=="cyusb_dev", RUN+="/usr/bin/run_code.sh R"

run_code.sh is
Code:

#!/bin/bash

nohup /home/ivb/"d.sh" &

exec /bin/bash
~

d.sh is script which calls gnome-terminal like
Code:

#!/bin/bash

sleep 1

/usr/bin/gnome-terminal

exec /bin/bash

1.why this gnome-terminal is not opening??
2.if i run any of sample code (with no call to gnome-terminal) it works fine with event of pluging.
3. if i run d.sh independentaly like
Code:

ivb@ivb-desktop:~$ ./d.sh
terminal gets open
4.but with link to udev .rule the d.sh script doent work fine the gnome-terminal never gets open

please kindly consider ma request n give solution and way to it.

Thanks & Regards
Rohan

dwhitney67 05-27-2013 09:01 AM

Quote:

Originally Posted by rohaanembedded (Post 4959835)
3. if i run d.sh like
Code:

ivb@ivb-desktop:~$ ./d.sh
terminal gets open

Rather than run your script as the current user that is logged into the system, try running it as another user (e.g. root).

If your system supports sudo, then try something like this:
Code:

$ sudo -i
<enter password>

# <path-to-script>/d.sh

What you will probably see is an error indicating that root user does not have permission to open the current display (which is in use by the regular user).

I would suggest that you plan an alternative to launching a terminal.

rohaanembedded 05-27-2013 09:23 AM

Quote:

Originally Posted by dwhitney67 (Post 4959845)
Rather than run your script as the current user that is logged into the system, try running it as another user (e.g. root).

If your system supports sudo, then try something like this:
Code:

$ sudo -i
<enter password>

# <path-to-script>/d.sh

What you will probably see is an error indicating that root user does not have permission to open the current display (which is in use by the regular user).

I would suggest that you plan an alternative to launching a terminal.


Dear sir,
Quote:

really Thanks for information is there any other way which can be used to open terminal n run code on that new terminal
please help me in this
Thanks & Regards
rohan

dwhitney67 05-27-2013 09:55 AM

Quote:

Originally Posted by rohaanembedded (Post 4959857)
really Thanks for information is there any other way which can be used to open terminal n run code on that new terminal

You do not need to open a terminal to run code; if you are able to execute a shell script, then that should be sufficient.

If you are seeking user input, then you may need to rely on something other than gnome-terminal.

P.S. It would be helpful to know what is it that you want to do, not how you want to do it.

rohaanembedded 05-27-2013 11:56 AM

Dear sir,

i have one usb device containing Cypress usb controller. i have developed one user space driver which does 4-5 fucntionalities like firmware download, getdescriptor(shows device descriptors), check_bus_speed, show_IDvendor,
this code i have developed using libusb and cyusb parent drivers (usb wrapper).
now i want ma device to have hot plug facility, that means whenever device is plugged in one terminal shud get opened and on that my developed code get executed automatically. and gives me options like press 1 for firware download 2. for this n 3. for this like interactive thing.
so i used .rule file (udev rules) for getting know that device is connect...
and what i am doing i have given in previous posts.

i am able to run code through script n get sum functionality on hot plug but i have to have interactive session where it ask me for options what i want to do
n here i am dnt knw wats going wrng terminal doesnt open.
so need one more option to make it happen or open the terminal

kindly consider ma request for help n do rply

thanks & Regards
rohan

dwhitney67 05-27-2013 01:41 PM

You might be able to get away with using 'gksu' to launch a terminal. However if you invoke 'gksu' as root, then the terminal will also be launched with root privileges (and this would be a bad idea). To prevent this, you can use the -u option to specify the user who currently is owner of the system display.

In it's basic form, gksu can be used as follows:
Code:

gksu gnome-terminal
If you know the target user:
Code:

gksu -u <user> gnome-terminal
where <user> is the user-id.

rohaanembedded 05-28-2013 12:14 AM

Dear sir,

i tried that also but found no Luck!!! :(

Quote:

#!/bin/bash


gksu -u ivb gnome-terminal

exec /bin/bash
~
i tried this in d.sh
but terminal is still not opening on the hot plug event. my other code runs on hot plug. but code containg gnome-terminal doesnt work atall
how to get rid of this :banghead:

thanks for your support sir,
please let me know about any solution

Regards
rohan


All times are GMT -5. The time now is 10:24 PM.