You are not logged in.
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
./.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
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
Offline
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
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
Offline
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.
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
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
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
Offline
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
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
Offline
I just need to found a way to set the title of the terminal
echo -ne "\033]0;Title Of Terminal\007"
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:
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
Last edited by Head_on_a_Stick (2022-04-15 10:56:00)
Brianna Ghey — Rest In Power
Offline
🙇 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.. )
Thanks
Last edited by SpongeBOB (2022-04-16 05:39:12)
Linux noob, plz be kind
Offline
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
Last edited by Head_on_a_Stick (2022-04-16 13:29:31)
Brianna Ghey — Rest In Power
Offline