You are not logged in.

#1 2017-08-19 11:29:12

Steve
Member
Registered: 2017-01-03
Posts: 642

Openbox autostart script to check updates

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

#2 2017-08-19 11:53:01

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

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  wink

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

#3 2017-08-19 11:58:02

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

To explain some more:

Steve wrote:
#!/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

#4 2017-08-19 12:17:46

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

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

#5 2017-08-19 13:21:03

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

Steve wrote:

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

#6 2017-08-19 13:40:02

Bearded_Blunder
Dodging A Bullet
From: Seat: seat0; vc7
Registered: 2015-09-29
Posts: 1,146

Re: Openbox autostart script to check updates

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

#7 2017-08-19 14:08:47

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

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

#8 2017-08-19 15:30:14

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

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

#9 2017-08-19 15:41:16

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

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

#10 2017-08-19 15:46:47

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

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

#11 2017-08-19 15:59:48

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

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  tongue

Offline

#12 2017-08-19 16:17:09

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

Head_on_a_Stick wrote:
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  tongue

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

#13 2017-08-19 16:24:35

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

Does removing the hold option make it do what you want?

Offline

#14 2017-08-19 16:26:32

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

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

#15 2017-08-19 16:29:18

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

^ 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  big_smile

Offline

#16 2017-08-19 16:34:41

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

Head_on_a_Stick wrote:

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

#17 2017-08-19 16:36:43

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

Head_on_a_Stick wrote:

^ 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  big_smile

Tim tams or shortbreads? Your not getting my cookies  tongue

Offline

#18 2017-08-19 16:56:07

Head_on_a_Stick
Member
From: London
Registered: 2015-09-29
Posts: 9,093
Website

Re: Openbox autostart script to check updates

^ Actually I've just munched out on biscotti (with tea) so I'm fine for now, thanks  smile

Offline

#19 2017-08-19 17:06:06

Steve
Member
Registered: 2017-01-03
Posts: 642

Re: Openbox autostart script to check updates

I like the sound of "chocolate cherry biscotti"... nice  smile

Offline

#20 2017-08-19 18:28:37

obscurant
Member
Registered: 2017-08-06
Posts: 150

Re: Openbox autostart script to check updates

For what it's worth, I check for updates in conky with:

${execi 3600 aptitude search "~U" | wc -l}

Offline

Board footer

Powered by FluxBB