LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Setup CRON jobs under root for another user. (https://www.linuxquestions.org/questions/linux-general-1/setup-cron-jobs-under-root-for-another-user-4175502885/)

khattakr 04-24-2014 03:56 PM

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,

szboardstretcher 04-24-2014 04:13 PM

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 :)

khattakr 04-24-2014 04:53 PM

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?

jefro 04-24-2014 07:38 PM

Think of cron as a user instead and give that user permissions to do task maybe.

eklavya 04-28-2014 12:32 AM

Quote:

Originally Posted by khattakr (Post 5158671)
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.


All times are GMT -5. The time now is 08:28 AM.