Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1482  / 3 Years ago, sat, june 19, 2021, 1:13:21

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?


More From » sudo

 Answers
3

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

[#23263] Saturday, June 19, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
herriail

Total Points: 11
Total Questions: 122
Total Answers: 118

Location: Peru
Member since Tue, Mar 16, 2021
3 Years ago
;