Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Advise please on scripts

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
gablea
Posts: 56
Joined: 2015-12-26 21:32
Location: United Kingdom

Advise please on scripts

#1 Post by gablea »

Hello everyone,

I hope someone can help me with something.

I have created a small script that loads some of the required modules for my EPoS system to work. But. I have a question I want to ask

I start my datasync app with /home/algpos/datasync/datasync.gambas /startsync

Does the script stop processing and wait until the above app exits or does it carry on. I need the script to wait until the app has completed so it can then start the app again but this time in a different mode (I have the /startsync that pulls everything from the server to the local database and then I have /rtsync that sets the application into a screenless mode and sends data to the server every minuite.)

The reason why I need the script to wait is so once the sync app has done the first full download I can then exit the app and then start it like

home/algpos/datasync/datasync.gambas /rtsync &
To put the application into the background (so it's running and keeping the databases in sync with out taking any screen up.

Can I do this or do I need to rethink my approach?

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1400
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 79 times
Been thanked: 175 times

Re: Advise please on scripts

#2 Post by steve_v »

gablea wrote: 2021-07-21 22:28Does the script stop processing and wait until the above app exits or does it carry on.
That would depend on exactly how you are starting your subprocess, and whether or not it forks.

You have provided insufficient detail to guess either of those (or even which interpreter your "small script" is running in), so sans crystal-ball, the only advice I can offer is to investigate the posix wait(1P) manual, and the manual for your script interpreter.

By default, bash (guessing) will wait for a subprocess as long as it remains a child process of the invoking shell. If a child process instead runs something in the background and exits, that something will be inherited by init and bash can't track it.
In the latter case you'll probably have to get creative with pidfiles and such.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

gablea
Posts: 56
Joined: 2015-12-26 21:32
Location: United Kingdom

Re: Advise please on scripts

#3 Post by gablea »

@steve_v
Thank-you for the replay and I am sorry for the delay in getting back to you

I am using a Shell script (bash) to boot my System (as it is the only thing I know) but I am more then open to learning something more reliable if you can recommend something.

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1400
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 79 times
Been thanked: 175 times

Re: Advise please on scripts

#4 Post by steve_v »

gablea wrote: 2021-08-09 19:04I am using a Shell script (bash) to boot my System (as it is the only thing I know) but I am more then open to learning something more reliable if you can recommend something.
Shell is fine, that's exactly what it's for. It just has quite a few corner-cases and idiosyncrasies is all. :P

TBH, how you go about your task is probably more down to how that "datasync.gambas /startsync" command behaves. If it doesn't fork any extra processes and returns a useful exit code, you'd just start it from your script normally, let bash wait for it to exit (default behaviour), then use said exit code to decide what to do next.
If not, well, I don't know gambas, but somebody else might if you post (or link) the scripts in question and show us what result you're getting now.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

gablea
Posts: 56
Joined: 2015-12-26 21:32
Location: United Kingdom

Re: Advise please on scripts

#5 Post by gablea »

@steve_v

When I start the datasync.gambas /startsync manually from the terminal it starts my software up and i can switch back to the terminal and i can see the blinking icon just sitting there (once my app exits it return to the folder I was in) so I assume this means the bash script was waiting for the process to end.

SO would I then just use the 'datasync.gambas /NormalSync &' to start my sync app in the background of the terminal and carry on to the next task right away?

steve_v
df -h | grep > 20TiB
df -h | grep > 20TiB
Posts: 1400
Joined: 2012-10-06 05:31
Location: /dev/chair
Has thanked: 79 times
Been thanked: 175 times

Re: Advise please on scripts

#6 Post by steve_v »

Pretty much. Appending "&" to a command will put it into the background and return control to the shell (or script) immediately. If you want to track it, the PID of said background process will then be in a variable named '$!'.

While they seem to be going away now, the old sysv init scripts Debian used before systemd are also a good source of inspiration for such things. start-stop-daemon in particular is handy as it removes the need to do a bunch of process tracking in bash.
Once is happenstance. Twice is coincidence. Three times is enemy action. Four times is Official GNOME Policy.

invoinvo
Posts: 7
Joined: 2021-08-11 08:07

Re: Advise please on scripts

#7 Post by invoinvo »

the script will exit automatically after it load all the modules even you have put it in the background using "&" nohup

Post Reply