1

Every time I want t use this software I have to type /etc/init.d/kerio-kvc {start|stop|restart} in terminal. How can I define a shortcut command in terminal to do that?

3 Answers 3

3

Although the above works, you will need to write 3 aliases.

Instead I suggest you use a function (assuming sudo is needed)

function kerio ()
    {
    case "$1" in
        start) sudo /etc/init.d/kerio-kvc start ;;
        stop) sudo /etc/init.d/kerio-kvc stop ;;
        restart) sudo /etc/init.d/kerio-kvc restart ;;
        *) echo 'usage kerio {start|stop|restart}' ;;
    esac
    }
3

Open the bashrc file on your /home

nano ~/.bashrc

Then create an alias for what you want, on the end of the file. Like:

alias startkerio='/etc/init.d/kerio-kvc start'

Oh, and to be possible to use your new command without relogging or rebooting do this:

source ~/.bashrc
4
  • But there's problem with promission and sudo doesn't work What should I do?
    – hamidfzm
    Dec 12, 2013 at 22:27
  • The problem is when you try to save the file? If it is, it's a case of not having write permissions, so do this: 'chmod +w ~/.bashrc' If it's not the case, put the result of 'ls -l ~/.bashrc' here Dec 12, 2013 at 22:34
  • No, when I try startkerio terminal wanted permission and sudo doesn't work!
    – hamidfzm
    Dec 12, 2013 at 22:45
  • Well,you must see the permissions of /etc/init.d/kerio-kvc because that's what asking for a permission. Does kerio-kvc works with sudo when it's executed directly? Dec 12, 2013 at 22:59
1

You most likely should create a script that do that for you. Create a file somewhere in /usr/sbin, lets call it script (you can change it) then, edit it and include the following:

 #!/bin/bash
 /etc/init.d/kerio-kvc "$@"

WARNING:

For this method I'm going to use the SETUID, which is extremally dangerous if you don't know what you are doing. That said continue.


Now, lets set some nasty things like setting up our permissions of read and execution:

sudo chown root:root /usr/sbin/script
sudo chmod a-w /usr/sbin/script
sudo chmod a+x /usr/sbin/script
sudo chmod u+s /usr/sbin/script

Done. Now run script {start|stop|restart} anywhere and there it's.

3
  • I would put the script in /usr/local/sbin and there is no need to setuid, just call the script with sudo (Just my 2c)
    – Panther
    Dec 13, 2013 at 3:21
  • @bodhi.zazen well, I'm trying to get him with the less keystrokes possible
    – Braiam
    Dec 13, 2013 at 13:27
  • so use a one or two letter alias rather then suggesting a security risk to save a few key strokes =) at least you added a caution.
    – Panther
    Dec 13, 2013 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .