To run crontab script with specific user

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To run crontab script with specific user
# 1  
Old 03-10-2020
To run crontab script with specific user

Hi Guys,

I am have made a below entry in crontab using root user and need to trigger the script every one hour using test user.
But the script is not getting triggered. Could anyone help
OS - Linux
Script - Bash
0 * * * * su test -c "/script_path/"

# 2  
Old 03-10-2020
cron is a scheduler that is very basic in its understanding, see that as if you were talking to a true idiot, you have to give all information and details on what is required to do the job scheduled... As it has minimalist environement, if anything more is needed, it needs to be found in the script etc...
su test

opens a new shell also as test only the does not inherit of test's env when he connects interactively...
So to be basic best practice is to write jobs for cron and not give command line stuff, your job should be like
# Set all needed variable
# Set needed environment

su test -c "/script_path/"
# exit

Now, why are you running this as root that su UID, rather than the desired UID ?
# 3  
Old 03-10-2020
Thanks for the inputs, Basically the crontab entry is only enabled for root users. I wanted to run my script using test user rather than as root. So is there a way to run as test user while scheduling from cron as root
# 4  
Old 03-10-2020
Try to write the job as shown, and show us what it gives...
by default only root is configured to use cron but you can customise and enable other users... The same for at
# 5  
Old 03-10-2020
Use the system-wide /etc/crontab that allows a user name to be specified.

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file.
# This file also has a username field, that none of the other crontabs do.
# m h dom mon dow user command
17 * * * * root run-parts --report /etc/cron.hourly
# 6  
Old 03-10-2020
Originally Posted by Master_Mind
Hi Guys,

I am have made a below entry in crontab using root user and need to trigger the script every one hour using test user.
But the script is not getting triggered.
How are you entering the cron job in the tables?? Are you using crontab command to enter the job or are you editing the crontab file directly? If you editing directly it's no surprise that it isn't being triggered because the cron daemon won't know about it (yet).
# 7  
Old 03-10-2020
Originally Posted by RudiC
Use the system-wide /etc/crontab that allows a user name to be specified.
How to add the entry with this option ? can you help with my script

0 * * * * script_path/

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script containing Curl doesn't run with crontab

Hello I have a problem with the crontab command when I run a code containing Curl on the command line it runs without fail but as soon as I program it with crontab it executes everything except the curl returns fail thank you for helping me to resolve this problem because since Monday I look... (14 Replies)
Discussion started by: beautymind
14 Replies

2. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

3. UNIX for Dummies Questions & Answers

Script does not run from a user specific cronjob.

Hello, I have two crontabs, one for the root and one for another user. There is a script in my configurations that has to send a email. The script works and sends the emails when I run it by hand with either the root or the user, and when I program it in the root's crontab. But! It does not... (3 Replies)
Discussion started by: Tralaraloro
3 Replies

4. Shell Programming and Scripting

run script through crontab using ksh

hi i have a script called the content is ls >> crontest.txt. if i run manually it's giving output.but if i scheduled in crontab it's not giving output. crontab entry: 02 * * * * /sms5/SMSHOME/eds_sh/ >> /sms5/SMSHOME/eds_sh/testfile/logfile 2>&1 I am using there... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

5. Shell Programming and Scripting

crontab fails to run script

OS is Ubuntu 8.04.3. When I run the command: /usr/bin/syslogMailer < /etc/syslog.pipes/criticalMessagesFrom a bash shell it works and i receive an email as per the script however when run from crontab it does not work. Can anyone explain why and how to fix it? /usr/bin/syslogMailer... (4 Replies)
Discussion started by: jelloir
4 Replies

6. Shell Programming and Scripting

Can run a ".sh" script as the user but not from the crontab

Hello Everyone, I am logged in as me. I created a script in the directory "/install/new" called "" which basically runs another script "" . The "" is a vendor provided application strart up script that came with the installation. This is also in the same directory as... (10 Replies)
Discussion started by: bhaire
10 Replies

7. Shell Programming and Scripting

Script not running properly when run from Crontab

Hi I am a novice Linux/Perl user and am struggling to overcome what I am sure is a simple problem. I am using a perl program to create a shell script daily containing between 10 and 30 "at -f" commands for the same day. Then I change the file attributes to allow the file to be executed. When... (2 Replies)
Discussion started by: simoncjones
2 Replies

8. AIX

Crontab cannot run by non-root user

Good morning everybody. I have just receiedv a complaint from our DBA saying that if he create a scripts to run some Oracle performance scripts using crontab and the scheduling part is ok but the job is failed when I checked on /var/adm/cron/log. I have tried his scripts using Oracle id directly... (4 Replies)
Discussion started by: kwliew999
4 Replies

9. Shell Programming and Scripting

How do i run a shell script without crontab.

Hi Folks, Could you please suggest me how to run a shell script on a solaris env without using crontab. I am actually trying to write a shell script which will grep "WORD" in the logfile andd sends a email.Thanks in advance. Thanks Sandeep. (3 Replies)
Discussion started by: sandeep anand
3 Replies

10. Shell Programming and Scripting

recurring run of sh script in crontab

Hello gurus. I have a problem: my crontab -e is looks like this: ORACLE_SID=bla-bla * 21 * * * (sqlplus hotback/hotback @/oracle/backups/bla-bla/scripts/hotback/daily_hotback.sql) 0 19 * * * /oracle/backups/dev10g/scripts/exports/ 0 1 * * *... (4 Replies)
Discussion started by: MarGur
4 Replies
Login or Register to Ask a Question

Featured Tech Videos