Shell script para rodar 1 comando por vez quando o outro terminar

1. Shell script para rodar 1 comando por vez quando o outro terminar

Fernando Jose Penna de Souza
fernandojose

(usa Red Hat)

Enviado em 09/01/2023 - 17:23h

Boa tarde usuários,

Preciso de um script para rodar 1 comando por vez e não pode rodar mais de 1 mesmo comando ao mesmo tempo:
Segue um exemplo do que fiz, mas quero melhorar, esse já está funcionando,
Se alguém puder ajudar, agradeço,

########### SERVER: SE02P745 #################
#!/bin/sh
#set -x
################################################################################################
# Definicao de variaveis e criacao de diretorios quando necessario. #
# VM Server: SE02P745 - PA3 #
# SE06J259 - PA3 #
# LUNs PA3 - Server SE02P745 #
# VEEAM_REPO_PA3_01 #
# VEEAM_REPO_PA3_02 #
# VEEAM_REPO_PA3_03 #
# VEEAM_REPO_PA3_05 #
# LUNs PA3 - Server SE06J259 #
# VEEAM_REPO_PA3_06 #
# VEEAM_REPO_PA3_07 #
# VEEAM_REPO_PA3_08 #
################################################################################################
DATE=`date +%Y-%m-%d_%H:%M`
TIME="`date +%Y%m%d%H%M%S`"
#Verificar se está a rodar
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`

while true
do

#Verificar se está a rodar
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`

if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-01"
echo "VEEAM_REPO_PA3_01" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_01 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`
if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-02"
echo "VEEAM_REPO_PA3_02" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_02 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`
if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-03"
echo "VEEAM_REPO_PA3_03" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_03 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`
if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-05"
echo "VEEAM_REPO_PA3_05" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_05 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
done





  


2. Re: Shell script para rodar 1 comando por vez quando o outro terminar

Alexa Bolada
alexabolada

(usa Debian)

Enviado em 09/01/2023 - 17:24h

Boa tarde usuários,

Você pode criar um script em Shell, para executar seus comandos um a um. Ele verificará se existe nenhuma instância do comando sendo executado e caso não exista ele executará o próximo comando na lista e assim sucessivamente.

#!/bin/bash

DATE=`date +%Y-%m-%d_%H:%M`

#Verificar se está a rodar
export RUNNING=`ps -Tcjstv | grep \"unmap\"| wc -l`

while true
do
#Verificar se está a rodar
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`

if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-01"
echo "VEEAM_REPO_PA3_01" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_01 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`
if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-02"
echo "VEEAM_REPO_PA3_02" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_02 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`
if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-03"
echo "VEEAM_REPO_PA3_03" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_03 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
export RUNNING=`ps -Tcjstv | grep "unmap"| wc -l`
if [ $RUNNING -le 1 ];
then
DATE=`date +%Y-%m-%d_%H:%M`
echo "TESTE OK-Running PA3-05"
echo "VEEAM_REPO_PA3_05" >> /compellent-script/logs.txt
echo $DATE >> /compellent-script/logs.txt
nohup esxcli storage vmfs unmap --volume-label=VEEAM_REPO_PA3_05 &
echo "###########################" >> /compellent-script/logs.txt
fi
sleep 3600
done






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts