joevallender
joevallender

Reputation: 4293

one particular command in bash script doesn't work when run by cron, all other commands do

I have a bash script that runs a few commands including rsync and this one below

rm -f $(ls -1t /nas/backups | tail -n +161)

If I execute the script myself on the cli, all commands work. However if run by cron all commands work except the one above.

No idea why. The files in /nas/backups are owned by root, but cron is running as root.

Any ideas? thanks

Upvotes: 0

Views: 429

Answers (1)

joevallender
joevallender

Reputation: 4293

Okay. So I'm a dummy.

My ls command returns a list of file names, not file paths! And cron wasn't running in the correct working directory.

Upvotes: 1

Related Questions