linux – bash script is started manually, but it will not start if you set it as a cron task


I have a bash script that makes a request to Postgresql and saves the result (overwriting) to a file after processing.



TEXTDATA="\copy (SELECT json_agg(t) FROM (SELECT itemData FROM items ) as t) to /path/to/my/file.json"

#Мой запрос использующий TEXTDATA

sed -i 's/}, \\n {/}, {/g' /path/to/my/file.json

If I manually call the script in the terminal:


Then it works correctly and saves the result to a file.

However, if I write to crontab (by running sudo crontab -e ) an entry like this:


30 * * * * /bin/bash /home/myName/

Then the script does not run every 30 minutes. Tried it both with SHELL / PATH and / bin / bash, and without – does not work.

Please tell me what I am doing wrong and how can I fix it?


As a result, for the script to work, I needed:

  1. Run crontab -e without sudo
  2. Remove PATH=/sbin:/bin:/usr/sbin:/usr/bin and /bin/bash , but leave SHELL=/bin/bash – it does not work without it.
  3. Set bash file permissions with sudo chmod 777 /path/to/

30 * * * * /home/myName/

Thank you all for your help.

Scroll to Top