0

I want to save output of command to a file that my current user do not have access to. But my user can have root access using sudo. I'm running for example:

sudo crontab -l > /var/BackUp/crontab
-bash: sudo: Permission denied

But I can run just sudo crontab -l So I think sudo relevant only to crontab command and as user do not have access to /var/BackUp/crontab it gives such error.

Is it possible to write output to a file that requires root access under current user?

Index
  • 275

2 Answers2

2

The redirection is not part of the sudo command. Depending on the operation you can do:

sudo bash -c 'crontab -l >/var/backup/crontab'

Or if the command doesn't need sudo:

crontab -l | sudo tee /var/backup/crontab
muru
  • 207,228
0

Test this:

sudo -i
crontab -l > /var/BackUp/crontab
Panther
  • 104,528
kyodake
  • 17,808