'Can't run xterm terminals on Ubuntu Desktop via SSH, just after reboot server
I am having a hard time starting xterm terminals on Ubuntu Desktop via SSH, just after reboot the servers.
Abstract
I have some servers running Ubuntu Desktop 18.04.
I need to automate this process:
reboot the server.
launch some processes on xterm consoles in the GUI.
Using the GUI is mandatory, because such processes are RPAs running some desktop APPs.
Instead of accessing servers via RDP one by one, and running the processes manually, I want to code some script to do it automatically.
My Script
My script is a Ruby script and it looks like this:
display = host.ssh.exec!("ps -ef |grep Xauthor | grep -v grep | nawk '{print $9}'").strip
s = "DISPLAY=#{display};export DISPLAY;/bin/bash --login -c \"xterm -e bash -c 'cd /home/bots/code/tempora;./shm.rb;bash'\" >/dev/null 2>&1 &"
stdout = host.ssh.exec!(s)
The Problem
The script above works fine if I previously accessed the server via RDP.
But If I run the script just after rebooted the server, it doesn't work.
I researched a bit, and I noticed that I can't get the display value if I didn't accessed the server via RDP previously.
Here is the proof:
Getting display code before and after access server via RDP
(please click to see the screen, because StackOverflow is not allowing me to post pictures)
I tried to run the command xhost +, but I am getting this error message: xhost: unable to open display ""
(please click to see the screen, because StackOverflow is not allowing me to post pictures)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
