Home > Net >  Weird behavior of runuser command in cron context
Weird behavior of runuser command in cron context

Time:12-30

i try to run a script which contains below code, when i run the same command from root level or any other admin account level it generated the dump file, but if i run it as a cron-job this line seems to not work as i cant find a dump_().sql file anywhere in the system.

Cron-jobs have been created with crontab -e for the root account and i can see them running in the syslog

echo $(runuser -l postgresql -c 'pg_dumpall -c > dump_'${DATE}'.sql')

I excpect to get the dump_DATE.sql file generated

CodePudding user response:

Dug a little further into the issue and found a solution.

It turns out that cron runs with a specific PATH set and as runuser was not in that PATH i had do modify my command to the below:

/usr/sbin/runuser -l postgresql -c 'pg_dumpall -c > dump_'${DATE}'.sql'

now cron-job generated the dump file

  • Related