Você pode usar o operador de controle em segundo plano (&) para executar um processo em segundo plano e no sleep
comando para aguardar antes de executar um segundo processo, ou seja, :
#!/usr/bin/env bash
# script.sh
command1 &
sleep x
command2
Aqui está um exemplo de dois comandos que imprimem algumas mensagens com registro de data e hora:
#!/usr/bin/env bash
# Execute a process in the background
echo "$(date) - Running first process in the background..."
for i in {1..1000}; do
echo "$(date) - I am running in the background";
sleep 1;
done &> background-process-output.txt &
# Wait for 5 seconds
echo "$(date) - Sleeping..."
sleep 5
# Execute a second process in the foreground
echo "$(date) - Running second process in the foreground..."
for i in {1..1000}; do
echo "$(date) - I am running in the foreground";
sleep 1;
done
Execute-o para verificar se ele exibe o comportamento desejado:
user@host:~$ bash script.sh
Fri Dec 1 13:41:10 CST 2017 - Running first process in the background...
Fri Dec 1 13:41:10 CST 2017 - Sleeping...
Fri Dec 1 13:41:15 CST 2017 - Running second process in the foreground...
Fri Dec 1 13:41:15 CST 2017 - I am running in the foreground
Fri Dec 1 13:41:16 CST 2017 - I am running in the foreground
Fri Dec 1 13:41:17 CST 2017 - I am running in the foreground
Fri Dec 1 13:41:18 CST 2017 - I am running in the foreground
Fri Dec 1 13:41:19 CST 2017 - I am running in the foreground
Fri Dec 1 13:41:20 CST 2017 - I am running in the foreground
...
...
...