ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Have you checked your permissions? When a program runs from cron, it usually executes as root. When you run a program from terminal, you are usually running it as yourself. Unless you are executing the script with sudo.
Right. So as root, shouldn't the script have access to all permissions? I wouldn't think I would need to modify them (but I could be wrong).
When I execute the script from the terminal (and it works perfectly) it does so as a regular user with no sudo escalations.
When a program runs from cron, it usually executes as root.
It depends. If your running crontab -e to add the cron job then it will run as that user unless you specify the user via the -u option. System cron jobs i.e /etc/crontab or /etc/cron.d run as the specified user in that cron job itself. /etc/cron.daily,hourly and monthly always run as root as far as I know.
In the posted script all /etc/ files are world readable so running as root is not required. What dropbox uploader script are you using? The one I found has a test to check and exits if not bash.
A typical cron default path environment is PATH=/usr/bin:/bin. Both 7z and the date command are located in /usr/bin which is why your original script could successfully create the archive. droptobox is probably located somewhere else which is why it failed to run from cron. You might of made a syntax error etc when modifying the script to include absolute paths.
A typical cron default path environment is PATH=/usr/bin:/bin. Both 7z and the date command are located in /usr/bin which is why your original script could successfully create the archive. droptobox is probably located somewhere else which is why it failed to run from cron. You might of made a syntax error etc when modifying the script to include absolute paths.
I doubt that there's a syntax error since it executes fine from the terminal manually with the absolute paths.
It would also help to see exactly how your script is called from cron. Is this script be run as 'root' or 'you'? cron will allow you to do either. If it can be run as 'you' it should not be run a 'root'.
I would suggest also generating a logfile. This can be done by redirecting all the output to a file:
yourscript > /home/you/backup.log 2>&1
This will redirect stout & stderr to the file.
Chances are the output give us a pretty good idea about what the problem is. It would also allow you to add some 'debug' code to you script.
Thank you everyone for your help! I was finally able to get this working.
It seems very silly, especially because the 7z program executed without the full path being included, but the script didn't go further than that. I added the full path for 7z as well, and now everything works flawlessly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.