Execute command for all windows in the screen [closed] - gnu-screen

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I use screen and sometimes I change my .bashrc profile. Therefore, I want to apply .bashrc changes for all screen windows. Unfortunately, screen reads profile only for creating new window and doesn't reload .bashrc for existing windows.
My screen session has one or more windows. Before attaching screen I want to execute command for each window. The command is simple "source ~/.bashrc".
I try:
screen -X stuff "source ~/.bashrc"`echo -ne '\015'`
It's worked perfectly only for one window. So I can't iterate through screen windows using "prev" or "next" command.
I already have read screen man, docs, and I event try to search solution of my problem :)
Can you direct me to right direction? Or maybe somebody already solved similar problem?

If you're using a recent version of screen you can use the -Q option, see original thread and this answer. This works here:
screen -Q windows | sed 's/[^0-9]*/\n/g; s/^\n//g' \
| while read; do
screen -S test -p $REPLY -X stuff "source ~/.bashrc"$'\n'
done
With:
$ screen --version
Screen version 4.01.00devel (GNU) 2-May-06
Note, if you have multiple session, name them with -S. In this case I'm working with a session called test. -p tells screen which window to send the command to.
Note also the use of ANSI-C quoting ($'\n').
When the -Q command executes, screen waits msgwait seconds before running the commands, work around this by setting msgwait to zero and reset it after execution i.e.
screen -S test -X msgwait 0
...
screen -S test -X msgwait 5
5 is the default value.

Related

xfce4-session "cannot connect display" error [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 11 months ago.
Improve this question
I'm trying to run xubuntu-desktop on WSL as per the tutorial given by many sites. But I can't seem to connect to the display of VcXsrv and it always shows:
xfce4-session: Cannot open display: .
Type 'xfce4-session --help' for usage.
If I run startxfce4, it says:
/usr/bin/startxfce4: X server already running on display muhammadsalmanafzal:0.0
xrdb: Connection refused
xrdb: Can't open display 'muhammadsalmanafzal:0.0'
xfce4-session: Cannot open display: .
Type 'xfce4-session --help' for usage.
Although, the VcXsrv window of Xlaunch is closed.
Can anybody help me look for the error? What am I doing wrong?
Also, when I first installed xubuntu-desktop, at the very end it said:
Errors were encountered while processing:
blueman
E: Sub-process /usr/bin/dpkg returned an error code (1)
And then I read somewhere to remove it, so I did and reinstalled xubuntu-desktop and no error was given.
If you are running WSL 1 then then, you need to add following line to .bashrc in home:
export DISPLAY=:0.0
and run bash again.
However, if you are running WSL 2 then you need get the IPv4 of you WSL network (since by converting to WSL 2, it becomes a network) by checking the ipconfig in Powershell and then export the relative to .bashrc
[EDIT]
I think after the windows update to 20H2, the above solution stopped working. So, as per the official recommendation of Ubuntu from their site, you can add the following lines in your ~/.bashrc and restart it.
export DISPLAY=:0 # in WSL 1
export DISPLAY=$(awk '/nameserver / {print $2; exit}' /etc/resolv.conf 2>/dev/null):0 # in WSL 2
export LIBGL_ALWAYS_INDIRECT=1
a better solution is run:
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}'):0
wsl2 changed when restarted and can't be fixed currently.
https://qiita.com/baibai25/items/5841b0592727893d960f
The following two approaches worked for me. I use WSL2.
Approach -1:
The title bar of VcXsrv says something like VcXsrv Server Display MACHINENAME:0.0.
Start xfce4 with this command: xfce4-session --display=MACHINENAME:0.0
Replace MACHINENAME with the name of your PC.
Reference: https://github.com/Microsoft/WSL/issues/1800#issuecomment-455791220
Approach-2:
Add the following line to .bashrc file.
export DISPLAY=MACHINENAME:0.0
Again MACHINENAME should be the name of your PC
Save the file and restart WSL2.
Now you can just use the command xfce4-session.

Debian login loop [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
If I try to login on a Debian with XFCE it gets a blackscreen for a few seconds, then it flashes really short and puts me back at the login screen.
The strange thing is, if I go into a terminal using Ctrl + Alt + F1 (Or any other F key) I can login, and get into the GUI using startx.
Everything works like usual.
I installed Debian the same way on 4 different machines but none of them had this error.
I used debian-8.2.0-i386-xfce.iso for installation with a USB stick.
Somebody has a idea what could cause this behavior?
I had the same problem using Jessie 8.6 with the kernel 4.7 with cinnamon, and I did almost the same: I just changed the ownership of the /home/user/.Xauthority file and it also worked:
chown user.user ./.Xauthority
After some research, I found an entry at Debian User Forums, where someone had almost the same issue, except that I could use startx and he didn't. The problem was that some of the hidden files inside the users home directory were owned by root. I still don't know why I could start the xserver from command line but at least I can login now with the GUI again.
The solution
I went into the command line using CTRL + ALT+ F1
Then I logged in as root and did a ls inside the home directory of the corrupted user.
cd /home/username -> ls -la
("-la" list hidden files, and the owner of the files)
depending on how many files are owned by root you can change the rights for seperate files, or be lazy like me and do:
chmod a+rwx *
(chmod changes the permissions for a usergroup)
"a" means for ALL users (i have just one user on the machine)
"+" means to ADD rights
"rwx" means read, write and execute
and * means all files inside this directory
That means, all users can now read, write (modify) and execute this files.
I know, its maybe not the cleanest solution but it worked for me.
I had this problem this morning and none of these fixes were working for me.
It turns out this was happening because my disk was full.
Deleting some large unused files fixed it after a restart.
This problem may occur due to corrupted xsession file, fix it by installing lxsession
sudo apt-get install lxsession
I had similar issues
CTRL+alt+f1 to login via CLI
Then,
chown username:username .Xauthority
worked for me.
For me the solution was not worked even I give every permission to every user blindly. However, I have found the problem in .profile in home directory where I used some export commands and added to the PATH environment variable. Some other files such as .bashrs, .xauthority, or .xsession might be cause of the problem. Double checked that files. First backup the files, then remove all added lines and see the results.

How do I list manually installed packages in Debian over SSH non-interactively? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 5 years ago.
Improve this question
Directly on my Debian box, I can run the following command to show manually installed packages:
aptitude search '!~M ~i'
This works great. If I SSH in from a remote box, and run the command, I also get the same result.
However, when I run the command as a batch, it does not produce the same result.
ssh user#server aptitude search '!~M ~i'
Since the process takes a bit of time to run, I execute ps aux | grep aptitude while running both variants, and the result appears to be the same.
What am I doing wrong?
PS. I am aware that dpkg -L can produce this information, but this is just the smallest example of what is broken, I intend to use !~pstandard !~pimportant !~prequired to filter out base packages as well, which I don't believe dpkg can do (but if it can, a solution with dpkg is welcome.)
Using information from Bash - Escaping SSH commands, I was able to create a command that worked:
ssh user#server $(printf '%q ' aptitude search '!~M ~i')
If target is a more recent debian/ubuntu you can use:
ssh user#server apt-mark showmanual

How do I find .bash_profile and add to my shell's initialization file? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am trying to upgrade ruby using rvm.
On the pragmatic site, it says:
The important part is to add the following line to the end of your shell's initialization file (.bash_profile):
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
How do I do this? Where is this initialization file?
Please help
It would be /home/$USER/.bash_profile, but would only be present if you're actually using bash as your shell. Other shells will use a 'dot file' with their name in them instead. You can view them with ls -ad $HOME/.*
There are two initialization files .bash_profile & .bashrc, both present in user home directory.
.bash_profile is initialized when you login with userid. .bashrc is initialized when you are already logged in and want to open one more terminal.
If you want to add some settings in both the file then you can do following
if [ -f ~/.bashrc ];
then
source ~/.bashrc
fi

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