I tried backing up my Crontab to file using following command: crontab -l > backup/crontab. But this creates only empty file into directory backup and no output is printed to terminal. Exit code of that command is 0.
If I do crontab -l without redirection I get expected output:
/5 * * * * /path/to/script
...
Why is my command failing to write my Crontab contents to file and what should I do the make this work?
I am using Centos 7.7 and following versions of Cron packages installed:
crontabs-1.11-6.20121102git.el7.noarch
cronie-1.4.11-23.el7.x86_64
cronie-anacron-1.4.11-23.el7.x86_64
Shell I use is GNU bash, version 4.2.46.
EDIT:
[user@host ~]$ crontab -l > backup/crontab
[user@host ~]$ ll backup
total 248K
drwx------. 28 user user 4,0K 31.10. 09:30 .
drwxr-xr-x. 7 user user 4,0K 1.10. 12:58 ..
-rw-rw-r--. 1 user user 0 31.10. 09:30 crontab
...
Backup is local directory and has following Selinux policy: staff_u:object_r:user_home_t:s0.
EDIT2:
crontab -l > /tmp/crontab works and other locations were I have write access work too but when target is inside my home directory it fails. I wonder if selinux is causing this.
ls -l backup/crontab? – Kusalananda Oct 31 '19 at 06:52staff_u:object_r:user_home_t:s0. – Madoc Comadrin Oct 31 '19 at 07:44crontab -l > ~/my_crontab– FelixJN Oct 31 '19 at 07:46