How to run a sudo command in crontab?

I am running OS X v10.5 and want to perform a simple daily backup with crontab.

I know to edit crontab is "crontab -e" and to run the copy command manually is "sudo cp -r -p /var/spool/imap/user /volumes/backup1"

Will will work in crontab  "0 1 * * 0-6 sudo cp -r -p /var/spool/imap/user /volumes/backup1" ??

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

this will _nearly_ work. You only have to precede 'sudo' and 'cp' by their path, e.g.
and you should enclose "sudo ... backup1" in double quotes " ".
.. read
if you run sudo crontab -e arent you editing roots crontab, and wont all cron jobs run as root then and NOT need the sudo portion?

Ive never run an sudo cronjob
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

1. What user is the cronjob setup as?
2. What is the sudo definition?
3. Why not just create a root cronjob?
artradisAuthor Commented:
Hi, How to I run a root conrjob? do I :
1. "su" to login as root,
2.  then "crontab -e" to create a root cronjob?

(this, your original question is the wrong way to go about it ... instead of getting an ordinary user to su[peruser] do a command, just log in as root and run/crontab the command)

For Comment Id 22927601:
1  Easier to login as root, but you can "su"
2  from here you can get at all .../user/directories)
now crontab -e
copy ...



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Mac OS X

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.