You are not logged in.
--- Moved from Scripts &etc ---
Hello
Im having some trouble trying to create a bash script the will do the following. I dont know much about bash scripts at all but thought i would give this a try alas i have not much idea what else to do.
1. autostart upon login in a terminal
2. run a command in the terminal automatically
My effort so far.
The script:
#!/bin/bash
x-terminal-emulator --hold && exec sudo apt-get -u upgrade
exit
So far all this does is open the terminal but does not input the command "exec sudo apt-get -u upgrade"
The openbox autostart command in ~/.config/openbox/autostart
(sleep 7 && update.sh) &
Im doing something wrong here, any help would be appreciated.
Thanks
Steve
EDIT: confirmed working version here: https://forums.bunsenlabs.org/viewtopic … 745#p58745
Last edited by Steve (2017-08-20 02:27:54)
Offline
This works for me (in OpenBSD):
x-terminal-emulator -hold -e 'exec doas pkg_add -u'
The -e flag allows commands to be executed directly
autostart upon login in a terminal
Any commands that should be run at the start of a terminal session can be added to the shell (initialisation) configuration file, in the stock BunsenLabs desktop this is ~/.bashrc
EDIT: disregard the above, the file you want to use is indeed the Openbox autostart file.
Last edited by Head_on_a_Stick (2017-08-19 11:54:43)
Offline
To explain some more:
#!/bin/bash x-terminal-emulator --hold && exec sudo apt-get -u upgrade exit
Because you have used a double ampersand after calling x-terminal-emulator, the following command (`apt-get -u upgrade`) will not be run until after the terminal emulator window has been (successfully) closed (and it will run in it's own subshell thanks to the exec()).
See http://mywiki.wooledge.org/BashGuide/Te … _.7C.7C.29 for more.
Offline
Hoas, that helped get me closer to my desired function thankyou. Im not sure on the double ampersand, for now its working so wont touch it.
So this script now loads the terminal and outputs the sudo command to check upgrades using the following. It brings up the password prompt and when entered does the desired command. Would be nice to name it somehow with the password prompt but i guess that would involve some bash trickery.
#!/bin/bash
x-terminal-emulator --hold -e 'sudo apt-get -u upgrade'
exit
Last edited by Steve (2017-08-19 12:19:27)
Offline
Would be nice to name it somehow with the password prompt
Not sure what you mean but you could try something like:
#! /bin/sh
x-terminal-emulator --hold --title='Performing full system upgrade...' -e 'sudo apt-get -u upgrade'
exit
The syntax for the title option may be different (it doesn't even exist for my xterm(1) variant) so check the man pages.
EDIT: this works for xterm:
xterm -hold -title 'Example' -e 'exec foo'
Last edited by Head_on_a_Stick (2017-08-19 13:36:12)
Offline
If you want to know how to set titles for the terminal, look at the entry for htop in the openbox menu file (that's how I found out when I wanted to do that).
HoaS beat me to it.
Last edited by Bearded_Blunder (2017-08-19 13:41:31)
Blessed is he who expecteth nothing, for he shall not be disappointed...
If there's an obscure or silly way to break it, but you don't know what.. Just ask me
Offline
Thanks for the input.
I was thinking more along the lines of a prompt similar to say a welcome script?
So lets say for example...
Please Check Updates....[Y/N]?
then it would either go ahead with checking if yes or close the terminal if no.
So if yes would bring you to....
[sudo] password for sc:
Depending on how you have sudo configured.
Offline
How about:
#! /bin/sh
while true; do
read -p "Shall we check for updates [y/n]? " yn
case $yn in
[Yy]*) sudo bash -c 'apt update && apt-get -u upgrade'; break;;
[Nn]*) echo "OK, nevermind."; exit;;
*) echo "Please answer yes or no.";;
esac
done
Last edited by Head_on_a_Stick (2017-08-19 18:49:41)
Offline
That works perfect Hoas, but how would that be automatically started in a terminal using openbox autostart config file?
Edit:
This line goes into openbox autostart config file.
(sleep 7 && x-terminal-emulator --hold -e update.sh) &
The terminal is unable to be closed with CTL-D or Q or Exit though, so something still missing. You can close it via the window border exit.
Last edited by Steve (2017-08-19 15:48:40)
Offline
Save the script as ~/bin/autoupgrade (for example), then use this line in the autostart file:
sleep 7 && x-terminal-emulator -hold -title "System Upgrade" -e "$HOME/bin/autoupgrade"
Offline
The terminal is unable to be closed with CTL-D or Q or Exit though
Remove the opening set of brackets and the ampersand at the end, you're fork()ing all over the place
Offline
Steve wrote:The terminal is unable to be closed with CTL-D or Q or Exit though
Remove the opening set of brackets and the ampersand at the end, you're fork()ing all over the place
The brackets are gone and no difference, excluding the ampersand means the rest of my autostart files commands do not work so this set of autostart commands needs to go to the bottom of the file.
But still no change in behaviour in my system.
The script works perfectly, but it does not go back to standard terminal output after the operation is finished, just hangs until you close it via the x on the window border.
Offline
Does removing the hold option make it do what you want?
Offline
I think i figured it out.
Instead of the "break" after "[Yy]*) sudo apt-get -u upgrade; " use exit as in "[Nn]*) echo "OK, nevermind"
#! /bin/sh
while true; do
read -p "Shall we check for updates [y/n]?" yn
case $yn in
[Yy]*) sudo apt-get -u upgrade; exit;;
[Nn]*) echo "OK, nevermind."; exit;;
*) echo "Please answer yes or no.";;
esac
done
Thankyou for your help Hoas, i owe you are beer or two.
Offline
^ Ah, good work.
Thankyou for your help Hoas, i owe you are beer or two.
You're welcome — I don't drink but I do accept payments in biscuits
Offline
Does removing the hold option make it do what you want?
Actually i was wrong in my last post, that worked when invoking the script via the terminal but not through the autostart config.
Yes removing hold executes the script and the terminal closes, but would be nice to keep it open at the default "sc@debian $"
Offline
^ Ah, good work.
Steve wrote:Thankyou for your help Hoas, i owe you are beer or two.
You're welcome — I don't drink but I do accept payments in biscuits
Tim tams or shortbreads? Your not getting my cookies
Offline
I like the sound of "chocolate cherry biscotti"... nice
Offline
For what it's worth, I check for updates in conky with:
${execi 3600 aptitude search "~U" | wc -l}
Offline