0

With Debian GNU/Linux 10 (buster), I'm using a simple script to save a PostgreSQL database and upload it to my Dropbox account with Dropbox-Uploader tool. I schedule this task with a crontab.

When I directly execute my script from the prompt everything is ok and well executed, but when it run from the crontab the upload action isn't execute (./dropbox_uploader.sh -d upload).

Am I missing something in execute permissions ?

The script (my_script.sh)

#!/bin/bash

Database dump

pg_dump -U postgres -d my_database > /home/my_user/date +%Y%m%d_my_database.sql

Upload to Dropbox

./dropbox_uploader.sh -d upload /home/my_user/date +%Y%m%d_my_database.sql date +%Y%m%d_my_database.sql

Permissions

 ls -l my_script.sh
-rwxr-xr-x 1 my_user my_user 732 Apr  7 09:19 my_script.sh

getfacl my_script.sh

file: my_script.sh

owner: my_user

group: my_user

user::rwx group::r-x other::r-x

ls -l dropbox_uploader.sh -rwxr-xr-x 1 root root 52481 Apr 6 16:01 dropbox_uploader.sh

getfacl dropbox_uploader.sh

file: dropbox_uploader.sh

owner: root

group: root

user::rwx group::r-x other::r-x

Cron

0 9 * * * /bin/sh /home/my_user/my_script.sh

I have read this post and this post, but I think I'm missing something with dropbox_uploader.sh execution permissions.

GeoGyro
  • 131
  • 1
    Replace relative paths (./filename) with absolute paths (/path/to/filename) – Panki Apr 07 '21 at 08:00
  • If you've written a bash script (as suggested by your #!/bin/bash) don't call it with sh; either use bash or better still make it executable and just treat it as any other program – Chris Davies Apr 07 '21 at 08:48
  • When I call it in the crontab ? What difference it makes ? I ask it for my own knowledge and to acquire good practices. – GeoGyro Apr 07 '21 at 08:58

1 Answers1

1

Modify your script and write the full path of the script dropbox_uploader.sh

#!/bin/bash
# Database dump
pg_dump -U postgres -d my_database > /home/my_user/`date +%Y%m%d`_my_database.sql

Upload to Dropbox

/home/my_user/dropbox_uploader.sh -d upload /home/my_user/date +%Y%m%d_my_database.sql date +%Y%m%d_my_database.sql

Jose
  • 26