LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-18-2020, 12:31 PM   #16
goldennuggets
Member
 
Registered: Feb 2003
Location: USA
Distribution: Kubuntu, Manjaro
Posts: 239

Original Poster
Rep: Reputation: 24

Quote:
Originally Posted by Steve R. View Post
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.
 
Old 02-18-2020, 12:32 PM   #17
goldennuggets
Member
 
Registered: Feb 2003
Location: USA
Distribution: Kubuntu, Manjaro
Posts: 239

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by astrogeek View Post
What doesn't work? You need to show us the script and the relevant directory and file permissions or we can't help.
I already did...it is posted above.
 
Old 02-18-2020, 12:48 PM   #18
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
Are you talking about in your script or in crontab? If the cron command doesn't use full paths it won't run. So in cronttab you need something like
Code:
* * * * *    /full/path/to/your/script
 
Old 02-18-2020, 12:48 PM   #19
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Quote:
Originally Posted by goldennuggets View Post
I already did...it is posted above.
Ah, sorry, I thought you were trying something different and was not waiting anxiously for Monday's test.

Still, it would be helpful if you could be explicit about what exactly is different from the previous run so that others can follow more easily.

Last edited by astrogeek; 02-18-2020 at 12:49 PM.
 
Old 02-18-2020, 12:50 PM   #20
goldennuggets
Member
 
Registered: Feb 2003
Location: USA
Distribution: Kubuntu, Manjaro
Posts: 239

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by astrogeek View Post
Ah, sorry, I thought you were trying something different and was not waiting anxiously for Monday's test.

Still, it would be helpful if you could be explicit about what exactly is different from the previous run so that others can follow more easily.
What is different is that I added in the absolute path to the command "droptobox" and now the cronjob doesn't even zip the file as it did previously.
 
Old 02-18-2020, 01:47 PM   #21
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,679

Rep: Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893
Quote:
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.

https://github.com/andreafabrizi/Dro...ox_uploader.sh

There might be something specific to your droptobox script that could be causing the problem.
 
Old 02-18-2020, 01:50 PM   #22
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,725

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Did you also add the absolute path to the zip command?
Everything in a script run from cron needs an absolute path...
 
1 members found this post helpful.
Old 02-18-2020, 01:50 PM   #23
goldennuggets
Member
 
Registered: Feb 2003
Location: USA
Distribution: Kubuntu, Manjaro
Posts: 239

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by scasey View Post
Did you also add the absolute path to the zip command?
Everything in a script needs an absolute path...
No. I'll try that too. I didn't think the zip would since it worked before. I'll give it a go, thanks!
 
Old 02-18-2020, 02:17 PM   #24
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,679

Rep: Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893Reputation: 5893
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.
 
Old 02-18-2020, 02:18 PM   #25
goldennuggets
Member
 
Registered: Feb 2003
Location: USA
Distribution: Kubuntu, Manjaro
Posts: 239

Original Poster
Rep: Reputation: 24
Quote:
Originally Posted by michaelk View Post
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.
 
Old 02-18-2020, 02:56 PM   #26
timj
LQ Newbie
 
Registered: May 2011
Location: Portland, Or
Distribution: Xubuntu
Posts: 3

Rep: Reputation: 0
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.
 
Old 02-25-2020, 10:06 AM   #27
goldennuggets
Member
 
Registered: Feb 2003
Location: USA
Distribution: Kubuntu, Manjaro
Posts: 239

Original Poster
Rep: Reputation: 24
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.

I very much appreciate the help and suggestions!
 
Old 02-28-2020, 09:44 AM   #28
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
@OP: How did you try to debug? Tried `set -xv`? Have you read this: https://www.linuxquestions.org/quest...0/#post5707383 ?
 
  


Reply

Tags
automation, bash script, cron, scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Force breaks to avoid eye strain (typing breaks) upnort Slackware 12 09-19-2019 03:43 PM
[SOLVED] Ways to prevent cron e-mails from particular bash script located in cron.daily? postcd Linux - General 2 08-22-2017 08:55 AM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 08:16 AM
cron not working from crontab nor form /etc/cron/cron.d. What did SuSE change? JZL240I-U SUSE / openSUSE 11 01-04-2007 01:57 AM
Can any one plz explain why/what for cron.d, cron.daily, cron.weekly etc are there. mavinashbabu Linux - Newbie 4 09-21-2006 01:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration