You are not logged in.
I am trying to place this script on my server so that it checks if my Mythbackend is running and restarts it if (I should say when, doggone thing lol) it crashes. Of course the command I use is sudo /etc/rc.d/mythbackend restart, and this user who gave me the script is not using Arch so I thought I'd ask the gurus here to help me figure out how to get it going.
First part is the script and then his cron instruction:
-bash-3.2$ cat ~root/cron/backend.sh
#! /bin/bash
if ps ax | grep -v grep | grep mythbackend > /dev/null
then
echo "Mythbackend service ok" > /dev/null
else
#echo "Mythbackend service is not running"
echo "Mythbackend is not running"
/etc/rc.d/mythbackend restart
fi
and in /etc/crontab I have:
#Check mythbackend is running
0-59 * * * * root /root/cron/backend.sh
Of course I see I have /etc/cron.daily, etc. so I'm unsure where to put it and how the cronjob will change on here, as well as of course how to get it running without needing me to enter the root password. TIA for any help
Offline
Here's my /etc/sudoers entry to allow me to run pacman:
paul night= NOPASSWD: /usr/bin/pacman
"man pidof" would probably help with a more pleasing result than that "ps/grep/grep" stuff.
As the user, "crontab -e" and insert the frequency/command to run, then "crontab -l" to check.
Last edited by vacant (2008-08-11 08:01:38)
Offline
Okay, so for me would this be right:
bobby= NOPASSWD: /etc/rc.d/mythbackend
??
Offline
I think you may need your host name between user and "=" (my host name is night).
Offline
Thanks! I have added this line:
bobby mythbox=NOPASSWD: /etc/rc.d/mythbackend
How does this "activate" do I need to log out and back in or?
Offline
I guess you have a root account on the server so why not run it as root (with the system crontab)? You gain very much nothing here by using sudo. Also, just in case if this server is publicly accessible, I'd never setup passwordless sudo for a normal user account.
Offline
Yes chimeric it is my home server, so how would I run it as root with system crontab? Sorry but I have never done this cron part before Thx for your help
Offline
Yes chimeric it is my home server, so how would I run it as root with system crontab? Sorry but I have never done this cron part before Thx for your help
same as user, just edit the root user's crontab instead. So bump yourself up to root first, and then run crontab -e
Offline
Thanks Zepp! Okay so just to be clear I don't have to change /etc/sudoers to add that nopasswd line, but I can just have my script added to a cronjob with sudo crontab -e and it will run the command of the cronjob without me having to enter root passwd?
Last edited by colbert (2008-08-11 23:11:21)
Offline