• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4942
  • Last Modified:

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" ??

Thanks.
Joo
0
artradis
Asked:
artradis
5 Solutions
 
woolmilkporcCommented:
Hi,
this will _nearly_ work. You only have to precede 'sudo' and 'cp' by their path, e.g.
/us/local/bin/sudo
/usr/bin/cp
and you should enclose "sudo ... backup1" in double quotes " ".
 
wmp
 
 
0
 
woolmilkporcCommented:
.. read
/usr/local/bin/sudo
0
 
Rance_HallCommented:
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
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
TintinCommented:
1. What user is the cronjob setup as?
2. What is the sudo definition?
3. Why not just create a root cronjob?
0
 
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?

Thanks
0
 
IncisiveOneCommented:
(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 ...

Cheers

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now