LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 04-24-2014, 03:56 PM   #1
khattakr
LQ Newbie
 
Registered: Apr 2014
Distribution: RHEL
Posts: 2

Rep: Reputation: Disabled
Setup CRON jobs under root for another user.


Hello Everyone,

Could someone please help me with below issue;

I have some performance scripts that run under 'khattak' user id. This is id is being used by few other users. The issue is, some users are entering the password wrong and after 3 consecutive passwords, my id is getting locked which causing the cronjobs not to run and affecting my servers. I cant stop users from using that id since this is an app ID. I am thinking of setting up all the scripts under root user so even if the "khattak" id gets locked out. performance scripts will still run. I thought adding su - khattak -c "command that I use in a script" would work but it is not working as expected. I know I am doing something wrong here. I get this error messsage;
su: invalid option -- 'r'
Try `su --help' for more information.
su: invalid option -- 'o'

Could someone please tell me what command to use in a script so if I setp cronjobs under root users , it will still run as khattak? Below is one of the scripts I am using. The /khattak directory and all subdirectories are owned by khattak user.

#!/bin/bash
#
#
su - khattak -c find /khattak/apt/axes/cache -type f -mmin +2 \! -name '*.out' -exec rm "{}" ";"

Thank you,
 
Old 04-24-2014, 04:13 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
Just a reordering of the command:

Code:
su -c 'find /khattak/apt/axes/cache -type f -mmin +2 \! -name \'*.out\' -exec rm "{}" ";"' khattak
If you are using RHEL, then you should have support and you can call Red Hat for questions such as this
 
1 members found this post helpful.
Old 04-24-2014, 04:53 PM   #3
khattakr
LQ Newbie
 
Registered: Apr 2014
Distribution: RHEL
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thank you szboardstretcher, The command worked but only when I execute it as a root user. When I set it up as a cron job it is not running. Do you know the reason behind that?
 
Old 04-24-2014, 07:38 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,974

Rep: Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623Reputation: 3623
Think of cron as a user instead and give that user permissions to do task maybe.
 
Old 04-28-2014, 12:32 AM   #5
eklavya
Member
 
Registered: Mar 2013
Posts: 636

Rep: Reputation: 142Reputation: 142
Quote:
Originally Posted by khattakr View Post
Thank you szboardstretcher, The command worked but only when I execute it as a root user. When I set it up as a cron job it is not running. Do you know the reason behind that?
because the command uses su and it needs password to perform the action. But root does not need it so it can be run as root.
But when you try to run it as normal user in cron, it asks password and it does not run it successfully.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where are cron jobs located when not under /var/spool/cron/root? NotionCommotion Linux - Newbie 6 09-07-2012 07:33 AM
execute root cron jobs props666999 Debian 1 09-07-2007 12:40 PM
Cron Jobs setup - Suse 10 mindjet SUSE / openSUSE 6 03-12-2006 12:47 PM
One user's cron jobs not running dcroxton Linux - Software 5 03-06-2006 03:33 PM
Can't run cron jobs as user, only root Kropotkin Linux - Newbie 5 11-10-2004 09:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:54 PM.

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