A
A
Andrey2016-07-19 16:29:04
bash
Andrey, 2016-07-19 16:29:04

How to “throw away” part of the script or wrap it in a screen?

Good day. I have a question like this. I'm still a beginner "clerk" =) So there are some developments in the bash. So, is it possible in some way, for example, to wrap part of the script (its execution) into a screen?! Well, so that he would not "create a queue" so to speak ?!
PS Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2016-07-19
@sim3x

All methods are different

#!/bin/bash
# отправить в бекграунд
source /path/to/sub_script.sh & 

# отправить в бекграунд и отвязаться от текущей консоли
source /path/to/sub_script.sh &!  

# man exec
exec /path/to/sub_script.sh

# man nohup
nohup /path/to/sub_script.sh

# cat << EOF | nohup sh
# cat << EOF | exec sh
# cat << EOF | sh &!
cat << EOF | sh &

# content of my sub_script.sh
echo `date` > /tmp/123

EOF


# замечание
# sh != bash
# если у тебя скрипт оттестирован на баше, то делай cat << EOF | nohup bash

S
Saboteur, 2016-07-19
@saboteur_kiev

Part of the script is unlikely, but this can be done with a separate command, or save part of the script in another script and call it in the background with
nohup

A
abcd0x00, 2016-07-20
@abcd0x00

So is it possible in some way, for example, to wrap part of the script (its execution) into a screen?

You can run it in the background by adding an ampersand at the end.
Example
#!/bin/bash

func1()
{
    for i in {1..5}; do
        echo 1
        sleep 2
    done
}


func2()
{
    for i in {1..5}; do
        echo 2
        sleep 4
    done
}

func3()
{
    echo 3
    func1 &
    sleep 1
    echo 4
    func2 &
    sleep 1
    echo 5
    wait
}

func3

exit 0

Вывод
[[email protected] sh]$ ./t.sh 
3
1
4
2
1
5
1
2
1
1
2
2
2
[[email protected] sh]$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question