简体   繁体   中英

How to cron a bash script which requires root user access to run

I have a bash script that has a function written in Perl script called in the bash script. But when I try to run the script in cron the cron is not able to fetch the script as it says it requires root user access. When I execute the script I switch to the data manager role to execute. What can I do so that cron can also execute the script?

Few suggested converting the bash script into csh script also for reference asked me to add

source /central/confg/global.cshrc

this is in the script but I am not good at shell scripting so I am having trouble converting bash script into csh script. If anyone has any ideas what can be done here please share.

add the below line into file: /etc/sudoers

$(USERNAME) ALL=(ALL:ALL) NOPASSWD: $(PATH TO SCRIPT)

The default user is root if no user is specified as a parameter when creating a cronjob. Give the script the executable permissions to run successfully and to set any environment variables the root user needs to run the script.

Note: The root user should not be used for security reasons unless necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM