UNIX for Beginners Questions & Answers

If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Execute Ubuntu 14.04 cronjob as non-root

cron, solved, ubuntu 14.04

👤 Login to reply
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-14-2017
cmccabe cmccabe is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 13 July 2018, 11:29 AM EDT
Location: Chicago
Posts: 1,229
Thanks: 742
Thanked 14 Times in 13 Posts
Execute Ubuntu 14.04 cronjob as non-root

I have created a cronjob that successfully executes and among other thing runs aria2c to download several files and save them to a folder. However, since it executes as sudo, the downloaded folder is saved with those permissions.
Is there a way to execute the cronjob so that the downloaded folder is saved as non-root? As of right now the additional scripts can not see the download as permissions are not the same. I have tried sudo chmod 777 /path/to/scripts, but that does not seem to help. Thank you .
Sponsored Links
    #2  
Old 12-14-2017
Neo's Unix or Linux Image
Neo Neo is online now Forum Staff  
Administrator
 
Join Date: Sep 2000
Last Activity: 18 July 2018, 8:47 AM EDT
Location: Asia pacific region
Posts: 14,558
Thanks: 1,028
Thanked 1,430 Times in 693 Posts
Since the cronjob executes as root; you can simply change your cron script to change the permissions and ownership (as you please) when the script executes.
Sponsored Links
    #3  
Old 12-14-2017
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 18 July 2018, 6:34 AM EDT
Location: NM
Posts: 11,440
Thanks: 637
Thanked 1,176 Times in 1,082 Posts
Pick another user, go into
Code:
crontab

as that user. Create a new entry for the job. The user should be one with suitable permissions to run other code later on against the downloaded file. Hopefully you have a group or some special acl that can allow this.

Make sure that the script does not require advanced permissions to run. This means setting permissions on the directory-ies where the script lives, and on the destination directory tree.
The Following User Says Thank You to jim mcnamara For This Useful Post:
cmccabe (12-14-2017)
    #4  
Old 12-14-2017
cmccabe cmccabe is offline
Registered User
 
Join Date: Nov 2013
Last Activity: 13 July 2018, 11:29 AM EDT
Location: Chicago
Posts: 1,229
Thanks: 742
Thanked 14 Times in 13 Posts
I added the cron to crontab -u cmccabe -e and crontab: installing new crontab. This user has the correct permissions to run the script. Thank you .

---------- Post updated at 07:48 AM ---------- Previous update was at 07:46 AM ----------

I tried to change the ownership and group of the scripts but not thatt cron script. Should that be chmod 775? Thank you .
Sponsored Links
    #5  
Old 12-14-2017
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 18 July 2018, 6:34 AM EDT
Location: NM
Posts: 11,440
Thanks: 637
Thanked 1,176 Times in 1,082 Posts
755 will suffice - any user should be able to execute the script. Note: you need to check what files and directories the script runs against. Same problem.
Sponsored Links
👤 Login to reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unable to execute glance from cronjob Shravani Shell Programming and Scripting 5 08-02-2013 07:18 AM
Cronjob to be execute today at 9pm coolboy98699 Shell Programming and Scripting 6 04-25-2013 06:25 AM
Execute Shell Script from CRONJOB reachravi70 Shell Programming and Scripting 1 12-19-2010 02:57 AM
How to execute cronjob running in a different machine? mridul10_crj Shell Programming and Scripting 1 09-27-2010 01:09 AM
need to have a cronjob which will execute certain scripts every hr aemunathan Shell Programming and Scripting 3 03-11-2009 01:06 PM



All times are GMT -4. The time now is 08:49 AM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?