Raised This Month: $32 Target: $400
 8% 

Solved [LINUX] Run a sh script that requres root to run in cronjob


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Krelle1911
Member
Join Date: Mar 2013
Location: Randers
Old 01-01-2022 , 12:33   [LINUX] Run a sh script that requres root to run in cronjob
Reply With Quote #1

Hi all

I have a script which renice all instances of srcds on the server. This script requires to be executed as sudo or root.

I want this script to be executed automatically (cronjob fx).

But when I target the script in cronjob, it doesnt execute, and I cannot figure out why. I set it up with the same command as for anything else.

The script is located in /home/srcds/renice.sh

I tried multiple things fx the cronjob on root user

Quote:
30 * * * * cd /home/srcds && sh renice.sh
I also tried to put it in non root users crontab with the command
Quote:
30 * * * * root cd /home/srcds && sh renice.sh
And also

Quote:
30 * * * * sudo cd /home/srcds && sh renice.sh
The script simply wont execute this way. If I execute it as sudo with sudo ./renice.sh, then it works as intended. And if I do sudo su root, and execute it on root user, it also works, even though srcds instances are executed from a non sudo user.

Any suggestions?

I really want to renice via this script. But if it cant be done, what do you guys use to renice srcds?


*** EDIT ***
Server is running Ubuntu 18.04
__________________

Last edited by Krelle1911; 01-01-2022 at 12:51.
Krelle1911 is offline
Krelle1911
Member
Join Date: Mar 2013
Location: Randers
Old 01-01-2022 , 12:51   Re: [LINUX] Run a sh script that requres root to run in cronjob
Reply With Quote #2

I solved it by using my brain.

Root user has privilege to execute a script owned by another user without using "cd" in crontab. In other words, it was solved by simply using the command below on the root user.


It renice all srcds to -19 ever hour at XX:00 24/7/365.
Quote:
0 * * * * /home/srcds/renice.sh
Thanks for the help brain.
__________________
Krelle1911 is offline
asdfxD
Veteran Member
Join Date: Apr 2011
Old 01-01-2022 , 15:42   Re: [LINUX] Run a sh script that requres root to run in cronjob
Reply With Quote #3

If it's just "renice srcds" than use simply in crontab instead of an extra script....

crontab -e as root:
0 * * * * renice -19 `pidof srcds_linux` >/dev/null 2>&1
asdfxD is offline
Krelle1911
Member
Join Date: Mar 2013
Location: Randers
Old 01-01-2022 , 16:51   Re: [LINUX] Run a sh script that requres root to run in cronjob
Reply With Quote #4

Quote:
Originally Posted by asdfxD View Post
If it's just "renice srcds" than use simply in crontab instead of an extra script....

crontab -e as root:
0 * * * * renice -19 `pidof srcds_linux` >/dev/null 2>&1
I Got the script working - it is basically the same thing, but includes some other things as Well. Thanks tho
__________________
Krelle1911 is offline
Reply


Thread Tools
Display Modes

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

Forum Jump


All times are GMT -4. The time now is 02:09.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode