LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-11-2013, 05:08 AM   #1
JJJCR
Member
 
Registered: Apr 2010
Posts: 554

Rep: Reputation: 26
Smile Script to restart


hi guys, how do I make a simple script to restart a service like:

/etc/init.d/kerio-connect restart

do I just need to key in that command in a script?

is there a way to prompt the user like:

Are you sure you want to restart?
Press 'Yes' to proceed 'No' to cancel.

Need your help guys, sorry so noob in linux scripting.

Thanks in advance.
 
Old 05-11-2013, 06:44 AM   #2
arunchinnachamy
LQ Newbie
 
Registered: Dec 2010
Posts: 4
Blog Entries: 1

Rep: Reputation: 0
Code:
echo "You sure want to restart the service followed by [ENTER]:"
read answer
if  ("$year" == "yes")
    /etc/init.d/apache2 restart
The code should give you an idea how you can perform the user confirmation. This page should help.
 
Old 05-11-2013, 08:25 AM   #3
JJJCR
Member
 
Registered: Apr 2010
Posts: 554

Original Poster
Rep: Reputation: 26
hi, thank you so much for you reply i tried this code Ubuntu VM

but it has an error
'r':command not found
's':command not found
'x':command not found etc. etc.

Please help guys,i just tried whether the script is able to capture the keys but it does not work it throws some error.

any help is greatly appreciated.

Code:
#!/bin/bash
#This script will restart, start or stop the Kerio connect service

echo "Press the letter followed by enter, "R" to restart Kerio Connect service, "X" to stop to restart Kerio Connect service, "S" to start"

read answer

if ("$answer" == "R" || "r"); then

#/etc/init.d/kerio-connect restart

echo "You press R or r"

elif ("$answer" == "X" || "x"); then

#/etc/init.d/kerio-connect stop

echo "You press X or x"

else ("$answer" == "S" || "s"); then

#/etc/init.d/kerio-connect start
#
echo "You press S or s"

fi
 
Old 05-11-2013, 11:25 AM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,210

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
Originally Posted by JJJCR View Post
hi, thank you so much for you reply i tried this code Ubuntu VM

but it has an error
'r':command not found
's':command not found
'x':command not found etc. etc.
That's because arunchinnachamy's post has the wrong syntax.

Code:
echo "enter stuff"
read answer
if [[ "$answer" == "yes" ]]; then
   echo yes
else
   echo something else
fi
 
Old 05-11-2013, 09:05 PM   #5
JJJCR
Member
 
Registered: Apr 2010
Posts: 554

Original Poster
Rep: Reputation: 26
hi guys, thank you so much for your help i came up with this one:

Code:
#!/bin/bash

clear

echo "Press S to start X to stop R to restart and press [enter]"

read answer

if [[ $answer == "S" || $answer == "s" ]]; then
   echo "You press S" 
# put the command here to be executed
elif [[ $answer == "X" || $answer == "x" ]]; then
   echo "You press X" 
# put the command here to be executed
elif [[ $answer == "R" || $answer == "r" ]]; then
   echo "You press R" 
# put the command here to be executed
else
  echo "Unrecognize choice"
fi
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script to restart a dead script nathanpayne Programming 9 07-22-2011 11:28 PM
[SOLVED] how to restart the pc for in a script? joesto Linux - Newbie 5 10-31-2010 02:23 AM
restart script glennbtn Linux - Newbie 1 07-20-2010 06:13 AM
MySQL restart script? Fuwex Debian 2 08-17-2005 03:23 PM
Restart script blablaman Linux - Newbie 1 08-20-2004 07:09 AM


All times are GMT -5. The time now is 01:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration