Friday, April 26, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 3330  / 2 Years ago, fri, november 4, 2022, 12:03:37

I've tried several times to test my script, but with no success. This is the script:



zenity --question --text "my text"
if [ $? -eq 1 ]; then
zenity --warning --text "my text"
else
ping -n -c1 192.168.180.112
# print result (0 se existir)
echo $?
if [ $? -eq 0 ]; then
scp -r ~/Documents/Processo/CONCLUIDO/* [email protected]:/home/posto-ensaios/Documents/Processo
fileName=$(inotifywait -e moved_from /home/posto-11v/Documents/Processo/CONCLUIDO | sed -r 's/^.*MOVED_FROM(,ISDIR)*s+(.*)$/2/g')
mail -s "$fileName" [email protected] < ~/Documents/personaproject/Programa/scripts/mail.txt
mv --backup ~/Documents/Processo/CONCLUIDO/* ~/Documents/personaproject/processos_terminados
zenity --info --text="my text"
else
zenity --warning --text "my text"
fi
fi


I've tried to run with the sleep command with "pipe" after sed and to change the order of the commands. When running the script in their terminal the problem is that inotify always keeps waiting for an action...



I need to guarantee that files are copied, moved and the $filename is sent in email...



Any help?

Thanks!


More From » scripts

 Answers
5

If you'd like to send a mail everytime a file has been moved from the watched directory, you'll need to set up a different process monitoring this and sending the mail.



For the reasons you have just described, it doesn't matter where you put the inotifywait command, since the mv command does not happen at the same time, you won't catch the required event.



But if you watched the directory from another process, the moving takes place while you're watching and you can detect any changes.



By building on the previous example, you can start with the following sample script.



while true
do
fileName=$(inotifywait -e moved_from /home/posto-11v/Documents/Processo/CONCLUIDO | sed -r 's/^.*MOVED_FROM(,ISDIR)*s+(.*)$/2/g')
mail -s "$fileName" [email protected] < ~/Documents/personaproject/Programa/scripts/mail.txt
done


Please fill in the required details, it works basically the same as the previous example.



Note:

There are a few caveats, for example it might miss some moves while the mail is sent. It depends on the quantity and frequency of moves.


[#37292] Saturday, November 5, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
urvedcaly

Total Points: 171
Total Questions: 118
Total Answers: 124

Location: Cape Verde
Member since Fri, Nov 27, 2020
3 Years ago
;