Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My crontab (running as user) contains the following command

00-59 00-23 * * *  /usr/bin/smbget -R smb://192.168.10.32/Data -u USER -p PASSWORD

But I am getting an error as

You don't have enough permissions to access smb://192.168.10.32/Data/

But the same command I can execute (running as user) from command line.

How to give permissions to crontab to solve the issue?

share|improve this question
    
maybe you should ask on serverfault.com –  Elzo Valugi Jun 9 '11 at 6:50
add comment

migrated from stackoverflow.com Jun 9 '11 at 14:14

This question came from our site for professional and enthusiast programmers.

2 Answers

I had the same problem, and it took me about 6 hours to work out the answer. You get it for free:

When you are logged in properly, you will have an environment variable USER=root - this will not be in your environment when you run a job from crontab.

To set an environment variable for one command in crontab, simply put it directly before your command (i.e. after the time/day specification). So in your case:

00-59 00-23 * * *  USER=root /usr/bin/smbget -R smb://192.168.10.32/Data -u USER -p PASSWORD
share|improve this answer
    
+1 You get a free upvote. –  Tom Wijsman Aug 25 '11 at 23:47
add comment

I would set up Autofs to take care of mounting the SMB file system. You can use a credentials file to keep it a bit more secure. From there, your cronjob is simply cp /mnt/smbshare/data /home/whomever/whereever.

Autofs won't leave the SMB share mounted forever, and it will help you eliminate the hassle of trying to figure out those SMB tools inside cron.

https://help.ubuntu.com/community/Autofs

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.