Bash script to launch a terminal window on another user's desktop
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Bash script to launch a terminal window on another user's desktop
Okay, I know it's possible to have a script launch a terminal on the desktop of the person executing it -- but how about another user's desktop? I have a backup script I run nightly and I'd like it to pop up a terminal window to display the log when it's done, but the script is run as root. Is there some way to do this -- have root launch a terminal window on my desktop? (Or, failing that, some similar approach that anyone can think of?)
You probably don't want a terminal command running from your backup host with the display on the backup client. A terminal will have a limited scrollback window, and giving your clients access to your backup host is probably not ideal.
A better solution would be mail the backup log to the user.
I'm sorry, maybe I wasn't clear -- this is just my personal computer, and when I said "two users" I just meant "root" and my own account. The crontab runs as root, so when I tried just using gnome-terminal to execute a command, of course nothing showed up on my desktop, since I never log in as root. When I tried it running a script as myself, it worked fine, but it doesn't work when I'm running the script as root. All the users in question are just me. Anyway, this seems easier to me than sending an email -- if I can just use less or something to display the log file, I can just glance at it and quit as long as everything looks good.
You can run a terminal window as root, and have it appear on your desktop.
You need to be sure your DISPLAY is set correctly in your script. Cron's run environment is limited, so you need to specify such things manually (environment variables, PATH, etc.).
You can run a terminal window as root, and have it appear on your desktop.
You need to be sure your DISPLAY is set correctly in your script. Cron's run environment is limited, so you need to specify such things manually (environment variables, PATH, etc.).
You're right, when I tried it from "su" it worked okay. But I changed my script, and put the line
$DISPLAY=:0.0
before the line where I launched the gnome-terminal, but it still doesn't appear to have worked.
You may not have authorization to access your regular users display as root.
Run:
Code:
xauth extract - $DISPLAY | sudo xauth merge -
In a terminal in your Gnome session. You are sending a cookie for your display to the root user and merging it with root's .Xauthority file.
That was my first hypothesis, but after reading Mr. C's comment I think he was right. I did some experimenting and if I just run "sudo gnome-terminal" from a terminal, it launches a gnome-terminal that belongs to root (I can tell, because root doesn't have the same colors specified as I do), and I can launch another gnome-terminal from there and it pops up too.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.