How assure that gnome-terminal is displaying the correct hostname on window title? - ssh

I am looking for a solution that would update the window title to the current host.
I am usually doing ssh to different boxes and I observed that the window title in Gnome Terminal (3.0.1 from Ubuntu 11.00) is not correctly updated. Currently it displays "user#localcompure: path" - and I want to be updated after I do a ssh.
I should note that I am looking for a solution that will not require me to change settings on any machine I'm connecting to.

I'm looking to do the same here, the functionality works fine in konsole(kde's terminal app) but not from within gnome-terminal. The best solution I have found thus far is to invoke this by using a separate app with the following:
#!/bin/bash
#!/bin/bash
SETTP='MY_PROMPT="$HOSTNAME:$PWD\$ "'
SETTP="$SETTP;"'MY_TITLE="\[\e]0;$HOSTNAME:$PWD\a\]"'
SETTP="$SETTP;"'PS1="$MY_TITLE$MY_PROMPT"'
ssh -t $1#$2 "export PROMPT_COMMAND='eval '\\''$SETTP'\\'; bash --login"
found and copied from:
https://unix.stackexchange.com/a/40337?sgp=2

Related

How to create a Linux GUI app short cut for WSL2 on Windows10?

I have properly installed and setup WSL2. It works fine.
I also setup X11 forwarding and X server (VcXsrv). I can launch GUI apps such like konsole or gvim or even google-chrome from a bash shell.
Now I want to launch konsole by simply double clicking a short cut on the desktop without launching the bash command mode terminal. How should I do it?
I tried running this in cmd:
> wsl /usr/bin/konsole
and it reports:
qt.qpa.xcb: could not connect to display
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
I'm guessing it is because some X11 forwarding configurations were not properly setup, so I created a k.sh as follows:
#!/usr/bin/bash
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
export LIBGL_ALWAYS_INDIRECT=1
/usr/bin/konsole &
The first two lines were the X11 settings in my .bashrc, the last line launches konsole.
It works fine under bash environment; but when I ran
wsl k.sh
from windows cmd environment, it silently quitted without launching the konsole.
I'm out of ideas. What should I do to directly launch konsole or other Linux GUI apps under windows without having to getting into bash?
Thanks in advance.
You are asking about two different command-lines, and while the failures in running them via the wsl command have the same root-cause, the underlying failures are likely slightly different.
In both cases, the wsl <command> invocation results in a non-login, non-interactive shell where the command simply "runs and exits".
Since the shell is non-login/non-interactive, your startup files (such as ~/.bashrc and ~/.bash_profile, among others) are not being processed.
When you run:
wsl /usr/bin/konsole
... the DISPLAY variable is not set, since, as you said, you normally set it in your ~/.bashrc.
Try using:
wsl -e bash -lic "/usr/bin/konsole"
That will force bash to run as a login (-l), interactive (-i) shell. The DISPLAY should be set correctly, and it should run konsole.
Note that the quotes probably aren't necessary in this case, but are useful for delineating the commands you are passing to bash. More complicated command-lines can be passed in via the quotes.
As for:
wsl k.sh
That's likely a similar problem. You are doing the right thing by setting DISPLAY in your script, but I notice that you aren't using a fully-qualified path it. This would normally work, of course, if your script is in a directory on the $PATH.
But I'm guessing that you might add that directory to the $PATH in your startup config, which means (again) that it isn't being set in this non-login, non-interactive shell.
As before, try:
wsl -e bash -lic "k.sh"`
You could also use a fully-qualified path, of course.
And, I'm fairly sure you are going to run into an issue with trying to put konsole in the background via the script. When WSL exits, and the bash shell process ends, the child konsole process will terminate as well.
You could get around this with a nohup in the script, but then you also need to redirect the stderr. It's probably easiest just to move the & from the script itself to the command-line. Change your k.sh to:
#!/usr/bin/bash
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
export LIBGL_ALWAYS_INDIRECT=1
/usr/bin/konsole
Then run it with:
wsl -e bash -lic "k.sh &"`
Finally, a side note that when and if you can upgrade to Windows 11, it will automatically create Windows Start Menu entries for any Linux GUI app you install that creates a .desktop file. You can manually create .desktop files to have WSL create Start menu items for most applications.
For reference, in Windows 11 it's easier. To run a GUI application without a terminal window popping up, you just need to call wslg.exe instead of wsl.exe.
So, for example:
target: C:\Windows\System32\wslg.exe konsole
start in: C:\WINDOWS\system32
shortcut key: None
comment: Konsole
This tutorial shows how to install VcXsrv and and edit .bashrc to ensure that the "DISPLAY env var is updated on every restart".
DISPLAY env var needs to be dynamic setting.
I've used it successfully with WSL2 on Windows10 Version 21H2 (OS build 19044.2130) to run Chrome, Edge, and thunar. I'm using the Ubuntu 20.04 Linux distro.
To edit .bashrc follow these instructions.

Powercli to set "Autostart" on VM on ESXI not working

I am using versions:
ESXI 6.5.0 Update 3 (Build 14990892)
Power CLI VMware PowerCLI 11.0.0 build 10380590.
I have a VM that I am importing (ISO) into an ESXI and trying to set Autostart on the VM to "enabled" programmatically via some scripts, but it is not working. I am using the powercli command:
Set-VMHostStartPolicy (Get-VMHost | Get-VMHostStartPolicy) -Enabled:$true
I've also tried some variants of this command but none seem to work. I see the "event" get logged as "Reconfigure Autostart" under the "Recent Tasks" menu on the ESXI Web GUI as soon as I input the command, so its definitely configurating something, but when I double-check the state of the VM to see if Autostart is enabled, it still lists "Enable" as an option, implying Autostart is NOT enabled. Here's a screenshot:
Can anyone help me please? I just want to have this VM start automatically incase there is a power outage or server crash; But only in these cases, I want it to import powered OFF for the first time (as you can see in screen shot the EPS VM is imported but in a powered down state, which is what I want)
I think what you're doing is setting the host's default policy... You would think that would work. I'm using this code on ESXi 7.0 Update 1 to set the guest's policy:
$vmstartpolicy = Get-VM "$vm_name" | Get-VMStartPolicy
Set-VMStartPolicy -StartPolicy $vmstartpolicy -StartAction PowerOn
It has the same issue that it doesn't show in the web UI, (which somebody will complain about, and I'll have to fix) but it does auto-start the VM after a reboot, so at least it's a start (pun not intended).
Edit: After playing around a bit, I managed to find a solution that updates the UI.
plink -batch -ssh $user#$IP -l "$user" -pw "$password" vim-cmd hostsvc/autostartmanager/update_autostartentry "`$(vim-cmd vmsvc/getallvms | grep `"$vm_name`" | awk '{print `$1}')" "PowerOn" 0 1 "systemDefault" "systemDefault" "systemDefault"
Using plink to ssh into the host and run this vim-cmd, it updates the UI properly. Take note of the back-ticks (`) to escape the dollar signs (except the one with the $vm_name variable) and quotes in the sub command, so that powershell doesn't try to interpret them before sending them through the ssh tunnel. All the sub command does is get the all the VMs, use grep to filter down to the output line with the vm_name you specify, and use awk to print only the 1st column (the vm id required for the outer vim-cmd).

Linux Screen tab misbehaves on WSL environment

I use Ubuntu 18.04 on a WSL system and usually log on a Linux server through ssh to get some work done. When I activate 'screen' and use the tab key to autocomplete commands, my cursor goes to the end of line, and the formatting of my entire terminal breaks from then on.
When using vim in that condition on a screen terminal, if I go to the end of file and press down on more time, it erases the last line from the terminal.
It seems a kind of misinterpretation of some terminal signal. When using Putty or any other ssh client under the same circumstances, everything works fine, so I am pretty sure it is a problem with WSL environment, specifically.
Any ideas about what is the main issue and how to solve it?
I just came across this same exact issue and it appears to be a possible bug with Windows Console and certain $TERM values.
I have this problem when $TERM is set to screen-256color. The problem went away after setting $TERM to xterm-256color in .screenrc
$ cat ~/.screenrc
term xterm-256color

Trying to make a Webkit Kiosk on Debian with Raspberry Pi

I'm trying to build a Webkit Kiosk on a Raspberry Pi.
I found a good start at: https://github.com/pschultz/kiosk-browser
The things I want to do:
1) Start the kiosk without logging in (with inittab?)
Peter Schultz pointed out adding the following line:
1:2345:respawn:/usr/bin/startx -e /usr/bin/browser http://10.0.0.5/zfs/monitor tty1 /dev/tty1 2>&1
But he did not explain the steps to make this work (for noobs).
What I did is add his code to a personal git repository and cloned this repo to /usr/bin/kiosk and sudo apt-get install libwebkit-dev and sudo make.
The line to add to inittab will be:
1:2345:respawn:/usr/bin/startx -e /usr/bin/kiosk/browser http://my-kiosk-domain.com tty1 /dev/tty1 2>&1
If I do this, I generate a loop or some kind...
If you want to automatically load a browser full screen in kiosk mode every time you turn on the rpi you can add one of these two lines to the file /etc/xdg/lxsession/LXDE/autostart
#chromium --kiosk --incognito www.google.it
#midori -i 120 -e Fullscreen -a www.google.it -p
The first is for chromium and the latter is for midori, the rpi default lightweight browser.
Hint : Since we will use the rpi as a kiosk we want to prevent the screen from going black and disable the screensaver. Edit the autostart file:
sudo pico /etc/xdg/lxsession/LXDE/autostart
find the following line and comment it using a # (it should be located at the bottom)
##xscreensaver -no-splash
and append the following lines
#xset s off
#xset -dpms
#xset s noblank
Save, reboot.
More info on
http://pikiosk.tumblr.com/post/38721623944/setup-raspberry-ssh-overclock-sta
The upvoted answer suggest to run LXDE for it. You could also do it without such a heaver desktop enviorment. You could just start midori or chromium in an X session:
xinit /usr/bin/midori -e Fullscreen -a http://www.examples.com/
xinit chromium --kiosk http://www.examples.com/
Sometimes Fullscreen mode of midori is not working as expected and midori is not using whole screen. In these cases you could map it inside a very simple window manager like MatchBox to get real fullscreen. Due to xinit you have to wrap everything in a shell script.
#!/bin/sh
matchbox-window-manager &
midori -e Fullscreen -a http://dev.mobilitylab.org/TransitScreen/screen/index/11
Autostart could be done simply be using /etc/rc.local.
More information concerning screensaver issues and an automated restart could be found here: https://github.com/MobilityLab/TransitScreen/wiki/Raspberry-Pi#running-without-a-desktop
Chromium has a dependency problem on some debian derivate for arm architecture. For Cubian you find the bug report here. I am not sure if you could install chromium on latest Raspbian without problem.
But I really could recommend midori. It's very fast and support for modern web technologies is very good. As Chromium it is using webkit as rendering engine. If you miss some html5 / css3 features consider an update of libwebkitgtk (for example by using package of debian testing).
It's possible you haven't set the DISPLAY environment variable.
Try:
export DISPLAY=:0
/usr/bin/startx /usr/bin/browser
Or, browser can also take a display argument (so you don't need the environment variable):
/usr/bin/startx /usr/bin/browser :0
This works for me on Raspbian from a standard terminal shell (I'm logged in over SSH).
Updated for the current version of Raspbian (with Pixel desktop) install with noop 2.0.
I found you need to edit in two different places to get it to work.
/etc/xdg/lxsession/LXDE/autostart
/home/pi/.config/lxsession/LXDE-pi/autostart
So my configure file is:
# #xscreensaver -no-splash
#xset s off
#xset -dpms
#xset s noblank
#chromium-browser --kiosk --incognito http://localhost
And that's it.
You should probably start with checking if /usr/bin/kiosk/browser is working at all. You should start normal X session (graphical environment) on your RaspberryPi, launch terminal, try running this command:
/usr/bin/kiosk/browser http://my-kiosk-domain.com
and see what it prints on the terminal. Is this working? Do you see any error messages?
I'm trying to build a Webkit Kiosk on a Raspberry Pi.
I think Instant WebKiosk for Raspberry Pi could be useful for you.
See: http://www.binaryemotions.com/raspberry-digital-signage/

Creating new windows that run programs in screen

My .screenrc has some initialization code that opens some windows. It's neat.
What I want to do, while running screen is simply , with one command open a new screen window that is running a program.
It SHOULD be:
screen -t 'CADMIN' sudo cherokee-admin -b
This actually works, except that it also runs my .screenrc and opens up all of my
windows in a nested screen. FAIL.
I know I could use
^c ( to create a new window )
^cA ( to title it )
sudo cherokee-admin -b
and get the same effect, but I'd like to bring a little elegance to my life, which
is why I use screen and not some multi terminal thing.
Ideas?
Ok, I've got a somewhat palatable answer:
from the bugs page there is a discussion about problems using the screen -t invocation.
I've tried this and I find that screen -c /dev/null -t CADMIN sudo cherokee-admin -b actually works the way I originally thought it would. It's kind of nifty actually, -c calls nothing for the value of .screenrc, which does not open my glorious screen rig. I can live with this.
You could setup another .screenrc file that doesn't have all of the other windows in it then in your .bash_profile you could add something like:
alias scn="screen -c '.screenrc2' -t 'CADMIN' sudo cherokee-admin -b"
then all you would have to do is run $scn from the cli to open screen with the desired effect.
hope this helps
edit: Make sure you name the second .screenrc file something different (i.e. '.screenrc2')