How do I logout from a computer using shell? - linux

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}

Related

How can i do for run an app when ubuntu start?

Hi i tried in several ways to launch firefox by example at the beginning, obviously my machine enters automatically to ubuntu without ask for user or password, so i made a script like that : firefox url. And i put this script on cron with the parameter : #reboot + path of my script but it doesn't works, because firefox is not launched, is not only firefox i need to will able to launch as well gedit when ubuntu start, i hope that can i help me whit this.
By the way i have ubuntu 14.04
Thanks
Go to Startup Applications via dash
There, add firefox ...
You can specify the URL to open by writing the command:
firefox URL
This will open URL in the browser. No script needed...
you don't need a script for this.
Ubuntu has a GUI for managing startup applications called "startup applications"
Click the Search button at the top of the Unity bar
Search for "Startup applications" and press enter
In the GUI you can press "add" and enter a custom command of your choice
Also look at existing entries to see how it is done.

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.

Firefox/Chrome Shell for Ubuntu

I have googled my tail off - but can't seem to find what I am looking for. In Ubuntu (or any Linux distro for that matter) is there a way to set the GUI shell to only be Firefox or Chrome. Meaning - I don't need an entire desktop environment - just the one application.
I am pretty much trying to figure out a Linux equivalent to changing HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon from explorer.exe to firefox.exe.
By default, distributions are setup the way that a display manager is fired up right after the X server. For Gnome, that would be GDM, for KDE that would be KDM etc. What you need to do is to replace a Window manager with a custom application, which in your case is a web browser. Generally, you can achieve this by putting your command(s) into ~/.xinitrc and ~/.xsession files, for example:
#!/usr/bin/env bash
firefox &
For Ubuntu, this process is explained in details here. Other distros are quite similar.
Hope it helps. Good Luck!

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/

Access X11 display from empty environment (bash)

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).

Resources