When adding the following task to Crontab, it is not executed:
* * * * * sha256sum -c Ejercicio.sha256 >> /home/user/Escritorio/Ejercicio/example.txt
This line of code does what it does is verify the integrity of the files by comparing its checksum with the one previously calculated and stored in Exercise.sha256. And store the results in example.txt.
When executing that line manually in the terminal, there is no problem: in example.txt the results are saved correctly.
Also, when you schedule another task in crontab:
* * * * * date >> /home/user/Escritorio/ejemplo.txt
Crontab works correctly, that line of code runs smoothly. Therefore, I infer that the problem is not from Crontab.
However, as I said before, when you add to Crontab the first task does not run correctly: the example.txt file is created, but it is empty. And it remains empty even though the minutes pass.
I have tried to solve it in several ways: by programming a script tarea.sh that contains
#!bin/bash
sha256sum -c Ejercicio.sha256 >> example.txt
And write in crontab:
* * * * * /home/user/Escritorio/Ejercicio/tarea.sh
And it did not work either.
Another solution that occurred to me and that did not work was the following. In the script tarea.sh:
#!bin/bash
sha256sum -c Ejercicio.sha256
And in crontab:
* * * * * /home/user/Escritorio/Ejercicio/tarea.sh >> /home/user/Escritorio/Ejercicio/example.txt
The manually executed script worked correctly.
How could I solve this problem?
Thank you very much.
Edit: I ran the following command
sudo apt-get install postfix
And now when adding the task to Crontab in the following way:
* * * * * sha256sum -c /home/user/Escritorio/Ejercicio/Ejercicio.sha256 >> /home/user/Escritorio/Ejercicio/prueba.txt
In test.txt the expected result does not appear (verification of the integrity of the files), but the following appears
fichero1.txt: FAILED open or read
So it seems that the crontab does not stop working correctly by writing the path of Exercise.sha256. I checked if I manually worked the command with the path of Exercise.sha256 written:
sha256sum -c /home/user/Escritorio/Ejercicio/Ejercicio.sha256 >> /home/user/Escritorio/Ejercicio/example.txt
And the following error occurs:
sha256sum : /home/user/Escritorio/Ejercicio: error de lectura