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

Posted on 2008-02-01
Medium Priority
Last Modified: 2008-02-04

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


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


Question by:anshuma
LVL 48

Assisted Solution

Tintin earned 400 total points
ID: 20795331
Type crontab -e and enter

0 19 * * 4 /path/to/your script
LVL 48

Assisted Solution

hernst42 earned 400 total points
ID: 20795336
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"
LVL 40

Accepted Solution

omarfarid earned 1200 total points
ID: 20800869
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:

export EDITOR
crontab -e

Add line similar to

0 19 * * 4 /path/to/shutdownlistener.sh >> /path/to/shutdownlistener.log 2>&1
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.


Author Comment

ID: 20816306
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
LVL 40

Expert Comment

ID: 20816481
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.

LVL 48

Expert Comment

ID: 20817574
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Over the years I've spent many an hour playing on hardened, DMZ'd servers, with only a sub-set of the usual GNU toy's to keep me company; frequently I've needed to save and send log or data extracts from these server back to my PC, or to others, and…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question