Enviado em 14/01/2012 - 11:08h
Não sei muito de bash-scripts, mas alguem já estudado sobre o assunto poderia me ajudar com um problema? Bem, quero fazer o seguinte, quando eu rodar o tal script, ele vai ficar rodando e monitorando a pasta download, se a pasta download receber algum arquivo, ele deve ler o nome do arquivo e se (if?) por exemplo, tiver "google" em alguma parte do arquivo (arquivosgoogle.jpg exemplo), o script move o arquivo da pasta downloads para a pasta /home/user/google, alguém poderia me ajudar?Enviado em 14/01/2012 - 12:16h
#!/bin/bash
DIR_ORIGEM="/home/$USER/Downloads"
DIR_DESTINO="/home/$USER/google"
for ARQUIVO in $(ls $DIR_ORIGEM)
do
# -gt -> maior que
if [ "$(echo $ARQUIVO | grep google --ignore-case --count)" -gt 0 ]; then
echo "movendo: $ARQUIVO"
mv -v "$DIR_ORIGEM/$ARQUIVO" "$DIR_DESTINO/"
fi
done
Enviado em 14/01/2012 - 12:30h
V2.1
#!/bin/bash
DIR_ORIGEM="/home/$USER/Downloads"
DIR_DESTINO="/home/$USER/google"
PALAVRA_CHAVE="google"
for ARQUIVO in $(ls $DIR_ORIGEM)
do
if [ $(echo $ARQUIVO | grep $PALAVRA_CHAVE --ignore-case --count) -gt 0 ]; then
echo "Movendo: $ARQUIVO"
mv -v "$DIR_ORIGEM/$ARQUIVO" "$DIR_DESTINO/"
fi
done
Enviado em 14/01/2012 - 13:05h
V3 Final
#!/bin/bash
escanear_e_mover()
{
echo "escaneando em $(date +%H:%M:%S)"
DIR_ORIGEM="/home/$USER/Downloads"
DIR_DESTINO="/home/$USER/google"
PALAVRA_CHAVE="google"
for ARQUIVO in $(ls $DIR_ORIGEM)
do
if [ $(echo $ARQUIVO | grep $PALAVRA_CHAVE --ignore-case --count) -gt 0 ]; then
echo "Movendo: $ARQUIVO"
mv -v "$DIR_ORIGEM/$ARQUIVO" "$DIR_DESTINO/"
fi
done
}
while :; #loop infinito
do
escanear_e_mover #chama a função
sleep 30 #tempo de espera em segundos
done
Enviado em 14/01/2012 - 14:26h
#!/bin/bash
escanear_e_mover()
{
echo "escaneando em $(date +%H:%M:%S)"
DIR_ORIGEM="/home/$USER/Downloads"
DIR_DESTINO="/home/$USER/google"
PALAVRA_CHAVE="google"
for ARQUIVO in $(ls $DIR_ORIGEM)
do
if [ $(echo $ARQUIVO | grep $PALAVRA_CHAVE --ignore-case --count) -gt 0 ]; then
echo "Movendo: $ARQUIVO"
mv -v "$DIR_ORIGEM/$ARQUIVO" "$DIR_DESTINO/"
fi
done
}
while :; #loop infinito
do
escanear_e_mover #chama a função
sleep 30 #tempo de espera em segundos
done
Subindo o Zabbix e Grafana no Podman com Pod
Habilitar a aceleração por hardware AMD AMF no OBS
Roubando bits (parte 2): como resolver questões rapidamente sem calculadora
Usando Linux para operar plataformas de análise gráfica na Bovespa (B3)
Sintaxe alternativa para encontrar arquivos por data com o comando find
URGENTE: pacote com versão maliciosa do ctx em Python estava presente no PyPI
Instalando Google Chrome no Ubuntu 22.04 LTS
ERRO:"PA... IS MISSING. PLEASE COPY IT FROM YOUR LEGITIMATE RTCW ... (0)
Sem opções de compartilhame... de tela no ZOOM - Ubuntu 22.04 LTS (0)