A
A
Andrey2017-09-01 22:17:58
linux
Andrey, 2017-09-01 22:17:58

How to make Wait wait for completion?

test1.sh:

#!/bin/bash

echo test
sleep 5
echo test1
sleep 2

test.sh:
#!/bin/bash

password=`zenity --password`

echo ${password} | sudo -S gnome-terminal -e "./test1.sh"

for word in word1 word2 word3 word4
do
  echo $word
  sleep 1
done

How can I make the test.sh script wait for the gnome-terminal command to complete?
I tried wait in different options that I found on the Internet, but none of them help.
After calling the terminal, the script immediately enters the loop.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Saboteur, 2017-09-01
@saboteur_kiev

there is a simple
shell1.sh option

echo $$ >> /tmp/wait.pls
echo Process started
sleep 3
echo Process stopped
rm /temp/wait.pls

shell2.sh
password=`zenity --password`

echo ${password} | sudo -S gnome-terminal -e "./shell1.sh"

while true
do
  if [ ! -f /tmp/wait.pls ] ; then
    echo "Done"
    exit 0
  fi
done

A
Andrey, 2017-09-02
@andreybold

Found an easier solution: xterm instead of gnome-terminal.
As it turned out, he does not jump to the next command.
Example:

#!/bin/bash

# Функция для запуска команды в xterm с определёнными настройками
# 1-й параметр либо команда либо ключ -s для запуска под root
# 2-й параметр либо пустой либо команда
x(){
  font_family=monospace
  font_size=10
  geometry=80x30
  font_color=lightgrey

  if ; then
    if ; then
      echo ${password} | sudo -S xterm -fa ${font_family} -fs ${font_size} -geometry ${geometry} -fg ${font_color} -e "$2;sleep 2"
    else
      echo "Нужен пароль!"
    fi
  else
    xterm -fa ${font_family} -fs ${font_size} -geometry ${geometry} -fg ${font_color} -e "$1;sleep 2"
  fi
}

# Функция проверки zenity диалогов с возможностью выхода
maybe_exit() {
  if ; then
    echo "Выход"
    exit $?
  fi
}

#sample
password=`zenity --password`
maybe_exit
x "./test1.sh"
x -s "apt update"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question