Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  34] [ 0]  / answers: 1 / hits: 96800  / 3 Years ago, sun, august 29, 2021, 10:20:42

I am trying to figure out how to write a script which would start program(s) in GNU Screen sessions(s) at system boot.
I am trying this:



#!/bin/bash
screen -S test -d -m -X $HOME/folder/folder/.program
screen -S test2 -d -m -X $HOME/folder/folder/.program2


but the command cant be executed because session is already detached?
The only thing that i need is run command in screen session and detach this session immediately.



Thanks for answers, but now i faced another problem. Script stops working after i put some variables for my "program and program2". Something like this:



#!/bin/bash
screen -S test -d -m $HOME/folder/folder/.program -f config.cfg


for some reason "-f config.cfg" got ignored. I am also tried to quote command and doesnt help too.


More From » scripts

 Answers
4

Did you really mean to put the at the end of the line? If not then try removing those - they escape the following character.



also, dropping the -X helps the setup work for me, for instance:



screen -S test -d -m -X touch /tmp/test


fails with No screen session found, however:



screen -S test -d -m touch /tmp/test


works fine. As such I suspect the following will work for you:



#!/bin/bash
screen -S test -d -m $HOME/folder/folder/.program
screen -S test2 -d -m $HOME/folder/folder/.program2





Remember, that if you run this at boot time, $HOME is not the same as after you log in as a specific user. If you need to run it as a certain user you'll need to use the likes of su to run it as that user, and specifying the full path will remove any ambiguity:



#!/bin/bash
screen -S test -d -m su - username /home/username/folder/folder/.program
screen -S test2 -d -m su - username /home/username/folder/folder/.program2


Or, you would call the entire script above as su - username /path/to/your/script.


[#43399] Tuesday, August 31, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ibuteking

Total Points: 35
Total Questions: 128
Total Answers: 138

Location: Indonesia
Member since Thu, Oct 1, 2020
4 Years ago
;