shell script to stop a service and a cron entry for it

Hi,

On a Linux machine this is what I do :

sudo su -
cd /bia/opt/game/bin
./alphactl -s Listener stop

I need to create a shell script that will contain all this. So that on the command prompt I can say

shutdownlistener.sh

and how do I create a cron entry for it so that it is run every week on thursday at 7:00 PM

thanks
-anshu




anshumaEngineeringAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
Type crontab -e and enter

0 19 * * 4 /path/to/your script
0
hernst42Commented:
If you run the script via cron you don't need sudo run the script as root crontentry would look like:
0 7 * * 4 cd /bia/opt/game/bin && ./alphactl -s Listener stop

else try as script (untested)
sudo - "cd /bia/opt/game/bin && ./alphactl -s Listener stop"
0
omarfaridCommented:
In your shell script shutdownlistener.sh, put

cd /bia/opt/game/bin
./alphactl -s Listener stop

Then make it executable:

chmod +x shutdownlistener.sh

Add crontab job under root account using crontab command:

EDITOR=vi
export EDITOR
crontab -e

Add line similar to

0 19 * * 4 /path/to/shutdownlistener.sh >> /path/to/shutdownlistener.log 2>&1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

anshumaEngineeringAuthor Commented:
I also need to do sudo su -

but when I put this. The shell just changes and then nothing happens. Like this

sudo su -
cd /bia/opt/game/bin
./alphactl -s Listener stop

I really need this script first
0
omarfaridCommented:
why don't  you run the script under the root account rather than su - ?

su - is done for interactive switch to root account.

You may ask root user to schedule the crontab job under his account.

0
TintinCommented:
Either run the cronjob as root, or change the sudo entry to be:

user  ALL= NOPASSWD:  /bia/opt/game/bin/alphactl

Then you just have a cronjob that calls

sudo /bia/opt/game/bin/alphactl -s Listener stop
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.