The officially official Devuan Forum!

You are not logged in.

#1 2022-04-02 05:11:49

SpongeBOB
Member
From: Brussels
Registered: 2022-02-07
Posts: 101  

[SOLVED] Launching a terminal from a subshell ?

Hi everyone,

I've created a script that run only once after an user login for the first time.

I launch the script trough ~/.profile

Like this

.profile wrote:
./.OneTime.sh &
startxfce4

So I launch my script as a subshell with the & at the end of the command because I need xfce to have generated some files..
and If I do

.profile wrote:
startxfce4
./.OneTime.sh

My script will never be executed...

I would my script (.OneTime.sh) launch a terminal for the user

I've tried

xfce4-terminal -e 'passwd' 

But I don't see the terminal....

Any ideas ?


Linux noob, plz be kind big_smile

Offline

#2 2022-04-02 09:51:53

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Launching a terminal from a subshell ?

SpongeBOB wrote:

I would my script (.OneTime.sh) launch a terminal for the user

echo 'x-terminal-emulator &' >> ~/.xsessionrc

See also https://wiki.debian.org/Xsession & https://xyproblem.info/

Alternatively use XDG autostart:

mkdir -p ~/.config/autostart
cp /usr/share/applications/xfce4-terminal.desktop ~/.config/autostart/

I think Xfce has an autostart GUI buried away somewhere in their menu labyrinth.


Brianna Ghey — Rest In Power

Offline

#3 2022-04-10 05:28:51

SpongeBOB
Member
From: Brussels
Registered: 2022-02-07
Posts: 101  

Re: [SOLVED] Launching a terminal from a subshell ?

Thank you @HOAS,

unfortunately 

echo 'x-terminal-emulator &' >> ~/.xsessionrc

had no effect (visible, most probably it run in the background)

mkdir -p ~/.config/autostart
cp /usr/share/applications/xfce4-terminal.desktop ~/.config/autostart/

indeed start the terminal, but I would like it launch within -e 'passwd' is it possible ?

I edited the ~/.config/autostart/xfce4-terminal.desktop

was

...
Exec=xfce4-terminal --preferences

to

...
Exec=xfce4-terminal -e 'passwd' --preferences

but that's have no effect either

Last edited by SpongeBOB (2022-04-10 05:36:58)


Linux noob, plz be kind big_smile

Offline

#4 2022-04-10 10:20:12

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Launching a terminal from a subshell ?

SpongeBOB wrote:
mkdir -p ~/.config/autostart
cp /usr/share/applications/xfce4-terminal.desktop ~/.config/autostart/

indeed start the terminal, but I would like it launch within -e 'passwd' is it possible ?

Ah, I see, my apologies — I thought you just wanted to autostart a terminal emulator. The XY Problem link I provided explains why it is always best to explain exactly what you're trying to do rather than just ask about a specific problem.

SpongeBOB wrote:

I edited the ~/.config/autostart/xfce4-terminal.desktop

was

...
Exec=xfce4-terminal --preferences

to

...
Exec=xfce4-terminal -e 'passwd' --preferences

You have edited the wrong section. Revert that change and instead add -e passwd to line 173 (ie, the Exec line without the --preferences option). That works for me in GNOME 42 under Arch anyway.

EDIT: just read the OP again. To make this only run once per user we would have to call a script instead that checks for a marker file left after completion and only runs the terminal if the marker file is not present (and then creates the marker file afterwards ofc).

So something like this in ~/.config/autostart/oneshot.desktop:

[Desktop Entry]
Exec=oneshot

With this in /usr/local/bin/oneshot:

#!/bin/sh

marker="$HOME"/.oneshot

if [ ! -f "$marker" ] ; then
   # need to run the commands in a shell to prevent $marker being
   # created if the passwd command is exited before completion
   x-terminal-emulator -e sh -c "passwd && touch $marker"
fi

Remember to mark the oneshot script executable after creating it.

EDIT2: my ~.xsessionrc suggestion didn't work because you're using startxfce4 rather than startx. Read the Debian Wiki Xsession link I provided in my first post to get a better idea of how to launch the desktop "properly".

EDIT3: this also works:

[Desktop Entry]
Exec=oneshot
Terminal=true
#!/bin/sh

marker="$HOME"/.oneshot

if [ ! -f "$marker" ] ; then
   passwd && touch "$marker"
fi

But then the terminal briefly appears then closes if "$marker" is present, which doesn't happen with my first suggestion.

Last edited by Head_on_a_Stick (2022-04-10 18:54:03)


Brianna Ghey — Rest In Power

Offline

#5 2022-04-15 07:39:01

SpongeBOB
Member
From: Brussels
Registered: 2022-02-07
Posts: 101  

Re: [SOLVED] Launching a terminal from a subshell ?

Thank you HOAS !

The XY Problem link I provided explains why it is always best to explain exactly what you're trying to do rather than just ask about a specific problem.

I've just read it and it totally make sens. I think also it's legitimate that if a "noob" took time on Y and believe he is that close to solve Y and therefore X. He is thinking that it will take less time to explain Y instead of the all X[Y].
For my part, If I would need help with Y I will included the X as much as possible 😅

You have edited the wrong section. Revert that change and instead add -e passwd to line 173 (ie, the Exec line without the --preferences option)...

That work ! I've tried also -->

Exec=xfce4-terminal -e passwd && rm -rf ~/.config/autostart/

But of course it's not working, that would have been too easy big_smile

EDIT: just read the OP again. To make this only run once per user we would have to call a script instead that checks for a marker file left after completion and only runs the terminal if the marker file is not present (and then creates the marker file afterwards ofc).

Would you have a solution that instead of create a marker file, just delete the ~/.config/autostart/xfce4-terminal.desktop ?

I will try now (base on your examples)  and post-it if I manage...

out of topics: Damn I spend my ~life to be a windows guru and the conversion is hard, but must ! just for ethic.

Last edited by SpongeBOB (2022-04-15 08:29:32)


Linux noob, plz be kind big_smile

Offline

#6 2022-04-15 08:17:15

SpongeBOB
Member
From: Brussels
Registered: 2022-02-07
Posts: 101  

Re: [SOLVED] Launching a terminal from a subshell ?

Voila,

I've done it slightly differently

So I'm using /etc/skel/.config/autostart/oneshot.desktop

[Desktop Entry]
Exec=oneshot
Terminal=true

and here the /usr/local/bin/oneshot

#!/bin/bash
passwd
rm -rfv ~/.config/autostart/oneshot.desktop

way easier than my previous solution big_smile

I just need to found a way to set the title of the terminal .

btw @HOAS why are you using #!/bin/sh ?

Last edited by SpongeBOB (2022-04-15 08:34:47)


Linux noob, plz be kind big_smile

Offline

#7 2022-04-15 09:14:56

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Launching a terminal from a subshell ?

SpongeBOB wrote:

I just need to found a way to set the title of the terminal

echo -ne "\033]0;Title Of Terminal\007"
SpongeBOB wrote:

why are you using #!/bin/sh ?

Because Debian & Devuan both link /bin/sh to dash, which is significantly lighter, faster and less buggy than bash. The only reason to use bash is if you need the extra features (called bashisms).

And on a more practical level:

alpine:~$ bash
/bin/oksh: bash: not found
127alpine:~$

I dual-boot Arch & Alpine Linux but the latter doesn't have bash installed and I prefer to create portable scripts (which will also work on BSD and other UNIX-like systems).

See sh(1) & https://pubs.opengroup.org/onlinepubs/9 … hap02.html for the full /bin/sh POSIX specification.

EDIT:

SpongeBOB wrote:

I've tried also -->

Exec=xfce4-terminal -e passwd && rm -rf ~/.config/autostart/

But of course it's not working

The Exec line just runs a command but && is shell syntax so to make that work you would have to run it through a shell:

Exec=x-terminal-emulator -e sh -c "passwd && rm ~/.config/autostart/oneshot.desktop"

So no need for /usr/local/bin/oneshot wink

Last edited by Head_on_a_Stick (2022-04-15 10:56:00)


Brianna Ghey — Rest In Power

Offline

#8 2022-04-16 05:38:15

SpongeBOB
Member
From: Brussels
Registered: 2022-02-07
Posts: 101  

Re: [SOLVED] Launching a terminal from a subshell ?

🙇 Thanks again HOAS !!! that's a detailed answer, thank you so much !

I'm ashamed to ask, but does someone have a an explanation about

echo -ne "\033]0;Title Of Terminal\007"

 
I've man echo But this doesn't help to understand why the echo is going to the title.. (I've look also on some's search engine but found nothing.. hmm )

Thanks

Last edited by SpongeBOB (2022-04-16 05:39:12)


Linux noob, plz be kind big_smile

Offline

#9 2022-04-16 09:01:43

Head_on_a_Stick
Member
From: London
Registered: 2019-03-24
Posts: 3,125  
Website

Re: [SOLVED] Launching a terminal from a subshell ?

The echo command is using ANSI escape sequences\033]0 sets a title in xterm (other terminals might need \033]2) and \007 (the bell character) unsets that option.

EDIT: or use

printf "\e]0;%s\a" "Please enter password"

Because echo -e is unspecified in the POSIX standard big_smile

Last edited by Head_on_a_Stick (2022-04-16 13:29:31)


Brianna Ghey — Rest In Power

Offline

Board footer