Crontab does not execute the task

1

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
    
asked by Montu 20.04.2018 в 14:29
source

1 answer

0

After trying different strategies I got it to work.

1.I gave you read, execute and write permissions to Exercise.sha256

chmod 777 Ejercicio.sha256

2.I moved the files to the / home / user directory (I do not know if this really helped to make it work but I point out the detail just in case).

3.And in crontab:

* * * * * sha256sum -c /home/user/Ejercicio.sha256 >> /home/user/example.txt

The example.txt file is generated correctly and contains the results that occur after running the command sha256sum -c Exercise.sha256.

    
answered by 21.04.2018 / 12:57
source