Access X11 display from empty environment (bash) - linux

Greetings!
I am implementing a backup solution, and I need to access the X11 display for getting a password from the user and displaying status information. I have tried setting $DISPLAY in the script to :0.0 (hardcoded), but xhost and misc complain that they cannot open the display. What should I do?
PS: The script is here: http://dpaste.com/109435/

You need the X Authentication information. I do not believe that xhost can "break in" to an X session and allow access without it (you'd need to have the user do it for you) and if you have it, then there is no need to use xhost at all.
Try
export DISPLAY=:0.0
export XAUTHORITY=/home/user/.Xauthority
and then running your commands.

As stated above, the user has to allow you to access their display. They need to perform the xhost + command. It's not really a good idea to just open your display up to anyone!
You'd be better off getting them to run
xhost +jeeger
or whatever your user is running as.
HTH
cheers,
Rob

Thanks, you brought me on the right path. Now I execute xhost +local: in my .xinitrc, and that allows me to access the X11 display (when I export DISPLAY).

Related

How to run linux without any DesktopEnvironment?

I have Manjaro installed on my system and for the Desktop Environment I have XFCE4 and for login manager LXDM everything works fine
but when I try to change some of the lxdm-config option I can't login to my user, the problem came from that I disable that option to shown the select session panel and after logout when I try to login again but after type password and press enter back to select user again!
I have no access to terminal or my user account to change the config again and back it to default or change the login session to xfce4
How can I access to terminal to change config or access to desktop or how can I fix this problem?
Thanks,
Try using ALt+Ctrl +FnKey. Fn key from 1 to 6 would lead you to the terminal shell. you can use all the bash commands over there.
You may restore the configuration file from there.
To reset display settings back to defaults (XFCE), this link may help you.

Error: Can't open display:

I am working my way through 'The linux command line' (http://linuxcommand.org/tlcl.php) . Since I don't have a local linux environment and I have to work in windows , I am telnetting into an Ubuntu 14.4 LTS instance on EC2 , with putty. On page 114 , when I run the xlogo command I get:
ubuntu#ip-172-31-22-65:~$ xlogo
Error: Can't open display:
How can I get this working?
xlogo will try to access the current Xserver to display a logo. If you're telneting to a box, you will not have an X server available, which is what that "can't open display" message is saying. It's trying to look at your DISPLAY environment variable to use that to show the logo on, but you don't have a display to use, and thus have nothing in your DISPLAY variable.
You will need access to an X server somewhere to do that step. One option would be to install cygwin on your Windows machine. Then you wouldn't need the remote linux box for most steps I imagine, because you could just use your local cygwin environment. Even if you want to use the remote box still, if you use cygwin and launch an xterm with it, you could ssh -X <host> and that will export your DISPLAY to that remote machine so it can display back on your windows machine.
As I mentioned in the comment under Eric Renouf answer, I am working thru the same book. That part of the book have some testing of creating users, groups, shifting users, group permissions etc. I found that I needed to log the same user out quite some times. The last time logging that user out, I got a message saying xlogo is terminatet, like it was hanging on that user?
After everyone was logged out, I logged in as sudo and everything worked again.

Need to schedule Cygwin Expect Script with Windows Task Scheduler

I am currently in the process of implementing a backup scheme to run a Cygwin Expect Script. What I would like to do is have task scheduler open Cygwin and run an expect script called Backups.
The issue that I run into is what I believe to be either variable or path based. I have the correct user from Active directory (we'll call it AD/svc_backup) set, and I am currently trying to just see if I can get the task scheduler to open Cygwin.
So far it will only open the program if I have the run only when user is logged on radio button pressed. This will open cygwin, but not let me run any further commands and gives me an error.
For example ls gives me "bash: ls: command not found" When it asks what program I want to start, I simply point it to the shortcut on my desktop and it then fills in the path C:\cygwin\bin\mintty.exe . Task scheduler does not seem like the most intuitive tool IMO but if I can get it to work I will use it. I also know that cygwin can use cron as well. Would cron be a better option?
I figured it out. So what the system means by the button "run only when user is logged on" radio button pressed" means is I want the script to run and I want to see it run with the local usr account. (interactive with the user)
The "run whether the user is logged in or not" button turns whatever script or program you run into a background service that has no user interactivity( you cant see it). By using the full path under the actions tab in cygwin I was able to tell it which script to run. Script path and options are like so:
C:\cygwin\bin\bash.exe -l -c C:/cygwin/home/svc_p_cisco_bkp/
I have been researching the -l and -c arguments and from what I can gather the -l means list the output and the -c means run these commands. This was not listed anywhere but from what I read it is as educated of an answer as I can give. Also I tested and the script will not run correctly without these variables.
I don't see the script start when I check the "run whether the user is logged in or not" button, but I can see the backups going to my destination folder. I do see it when "run only when user is logged on" however. What I did was get the script running the way I wanted while I could see it and then choose the "run whether the user is logged in or not" radio button when I know it was working correctly.
All is up and running and after exhausting reading of pages and pages about Windows task scheduler, and I am fully automated.

Opening multiple terminal with remote access

I am using remotely logged in to my work server through SSH. I have to work on terminal and it will be helpful if I can pull up multiple terminal to access multiple directories and files. How can I do that? I am a beginner. So, any help will be greatly appreciated.
screen is a great tool for this.
screen -m
will open a daemonized screen window and you can detach it to return to your primary shell with
Ctrl+A , then press D
To resume the screen use
screen -r
You can create multiple screens with names and resume them individually. Checkout the manpages for more info
You can use "screen" on you server to open more shell session in a "dedicated" environment so you can even disconnect from the server without loosing your shells (in case of idle, for example).
see http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/

How do I logout from a computer using shell?

How can I log out of my computer using shell such the log-in window appears again?
I need this functionality in one my Linux script.
Update:
I want to replicate the code working behind the Logout button of my Ubuntu.
Desktop Enviroment being used: GNOME
I think this does the job:
gnome-session-save --logout
Also, take a look at the --help output, maybe you want to use the --force-logout option.
Usage:
gnome-session-save [OPTION...]
Help Options:
-h, --help Show help options
--help-all Show all help options
--help-gtk Show GTK+ Options
Application Options:
--logout Log out
--force-logout Log out, ignoring any existing inhibitors
--logout-dialog Show logout dialog
--shutdown-dialog Show shutdown dialog
--gui Use dialog boxes for errors
--display=DISPLAY X display to use
Your question is a bit vague. Are you trying to log out of a graphical session of a desktop environment (such as KDE/Gnome), as if the user clicked on "log off"?
Then you need to find out if/how the desktop environment supports scripting to log out. On KDE for example you can use kquitapp.
Try restarting the display manager using one of the following, depending one which one you're using. You'll obviously have to have the proper permissions.
/etc/init.d/xdm restart
/etc/init.d/kdm restart
/etc/init.d/gdm restart
It's a bit of a hack, but the way that screen's power detach does this is to determine its parent pid and send it a SIGHUP. (Clarification: This closes only the shell, so only works if you're running from a console - not a graphical login - so may not be what you're looking for.)
Type in terminal
gnome-session-quit
or
pkill -kill -u {Username}

Resources