Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Create an Icon for sudo command?

  1. #1
    Join Date
    Nov 2007
    Beans
    120

    Question Create an Icon for sudo command?

    my problem is that my MX5000 keyboard and mouse loose contact with the bluetooth software after just maybe 30 minutes of inactivity.

    my current solution is to break out the wired keyboard and mouse, which are currently permanent fixtures atop my case because of this, open a terminal and typ in
    Code:
    sudo /etc/init.d/bluetooth restart
    and then type in my PW

    i have to do this very frequently. and mind you, this is an HTPC in my living room - yeah, eye-swore from hell...

    so what i would like to have is a icon on my desktop that i click and it does this for me, PW included, so that i can at least get the wired keyboard back in storage...

    so what do i need to do to get this created?

  2. #2
    Join Date
    Nov 2006
    Beans
    380
    Right click the Desktop and choose "create launcher". For the command enter
    Code:
    gksudo /etc/init.d/bluetooth restart
    Comments, name and custom icons are your choice.

    You'll have to enter the password whenever you run the command though. I would be very surprised if there is any way of including the password within the command - which is the sticking point for you. I would look to see why the bluetooth connection keeps getting dropped when the keyboard or mouse is inactive.
    Last edited by SPr; May 1st, 2008 at 06:26 PM.

  3. #3
    Join Date
    Jun 2006
    Location
    Solihull, UK
    Beans
    1,413

    Re: Create an Icon for sudo command?

    There is a way of making sudo not ask for a password, but it isn't recommended and I'm not going to post how to do it. If you really want to be able to do it, then you can find it by searching Google.

  4. #4
    Join Date
    Feb 2008
    Location
    Townsville, Qld Australia
    Beans
    1,065

    Re: Create an Icon for sudo command?

    Because sudo and its gui equivalent gksudo both require a password to be entered if you haven't done so in the last 10 minutes this is going to be a little more complex but is none the less achievable.

    Put the following into /etc/rc.local, this script is run at startup as root so there will be no need to use sudo, replace yourusername with...well you get the idea. To edit the file open a terminal an use
    Code:
    sudo gedit /etc/rc.local
    Code:
    #!/bin/bash
    #checks for a file in user home directory and if exists restarts service
    
    while [ 1 ]
    do
    sleep 120
    if [ -f /home/yourusername/.restartbluetooth ]; then
    echo "file found restarting service"
    /etc/init.d/bluetooth restart && rm /home/yourusername/.restartbluetooth
    else
    echo "file not found looping"
    fi
    done
    After entering this into the file ensure that the file is executable using
    Code:
    sudo chmod +x /etc/rc.local
    Now create a launcher on your desktop using whatever icon/name you want with the following command
    Code:
    touch /home/yourusername/.restartbluetooth
    This will create the file that the rc.local script looks for resulting in the service being restarted.
    Last edited by ryanhaigh; May 1st, 2008 at 06:32 PM. Reason: got rid of comments, they made it harder to read
    Registered Linux User #464572
    journal.ryanhaigh.net
    www.ryanhaigh.net

  5. #5
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Create an Icon for sudo command?

    Perhaps this is not the best fix possible, but here is a way to run
    Code:
    /etc/init.d/bluetooth restart
    as root every 30 minutes without having to type anything:

    Go to a terminal and type

    Code:
    sudo crontab -e
    Edit the root's crontab to look like this:

    Code:
    # m h  dom mon dow   command
    */30 * * * * /etc/init.d/bluetooth restart
    Last edited by unutbu; May 1st, 2008 at 06:32 PM.

  6. #6
    Join Date
    Mar 2006
    Beans
    251

    Re: Create an Icon for sudo command?

    If you want to run this commend(using command line or launcher)you can do it with sudoers, you can restrict without password for only this command. Right now I am not at linux machine so I can not give you more details, search google.
    http://www.google.ca/search?hl=en&q=...G=Search&meta=
    first link may help you,
    hope this helps for now.

  7. #7
    Join Date
    Feb 2008
    Location
    Townsville, Qld Australia
    Beans
    1,065

    Re: Create an Icon for sudo command?

    A more generic version where the service and username are specified as variables

    Code:
    #!/bin/bash
    #checks for a file in user home directory and if exists restarts service
    
    SERVICE=ddclient
    USERNAME=ryanhaigh
    
    while [ 1 ]
    do
    sleep 2
    if [ -f /home/$USERNAME/.restart$SERVICE ]; then
    echo "file found restarting $SERVICE"
    /etc/init.d/$SERVICE restart && rm /home/$USERNAME/.restart$SERVICE
    else
    echo "file not found looping"
    fi
    done
    Registered Linux User #464572
    journal.ryanhaigh.net
    www.ryanhaigh.net

  8. #8
    Join Date
    Jan 2008
    Location
    /dev/null
    Beans
    2,793
    Distro
    Ubuntu 8.04 Hardy Heron

    Re: Create an Icon for sudo command?

    Quote Originally Posted by chrisccoulson View Post
    There is a way of making sudo not ask for a password, but it isn't recommended and I'm not going to post how to do it. If you really want to be able to do it, then you can find it by searching Google.
    Its posted in the wiki, so its not a problem talking about it. you just need to edit sudoers, but again its not something you should do lightly at a whim. https://help.ubuntu.com/community/Sudoers

  9. #9
    Join Date
    Nov 2007
    Beans
    120

    Re: Create an Icon for sudo command?

    i'm not looking to disable the need for a PW when runnning the command - i do still want some amount of security in this regard

    i was think of using bash to create an MD5 code of my PW and using that in a script related to the launcher keeping my PW safe even when being used automatically. or maybe i can assign my wallet to auto enter it when i click the icon?
    i dont know how to code at all, so maybe i'm missing some very basic concepts here

    edit: on second thought, if the md5 thing worked then they could still use that code to get to everythiung else... so ... i'm tired, that's my exuse, and i'm sticking to it!
    so then, maybe make the viewing/editing of this one icon PW restricted?...


    Quote Originally Posted by ryanhaigh View Post
    Because sudo and its gui equivalent gksudo both require a password to be entered if you haven't done so in the last 10 minutes this is going to be a little more complex but is none the less achievable.

    Put the following into /etc/rc.local, this script is run at startup as root so there will be no need to use sudo, replace yourusername with...well you get the idea. To edit the file open a terminal an use
    Code:
    sudo gedit /etc/rc.local
    Code:
    #!/bin/bash
    #checks for a file in user home directory and if exists restarts service
    
    while [ 1 ]
    do
    sleep 120
    if [ -f /home/yourusername/.restartbluetooth ]; then
    echo "file found restarting service"
    /etc/init.d/bluetooth restart && rm /home/yourusername/.restartbluetooth
    else
    echo "file not found looping"
    fi
    done
    After entering this into the file ensure that the file is executable using
    Code:
    sudo chmod +x /etc/rc.local
    Now create a launcher on your desktop using whatever icon/name you want with the following command
    Code:
    touch /home/yourusername/.restartbluetooth
    This will create the file that the rc.local script looks for resulting in the service being restarted.
    i've done everything you;ve said here. replaced it with my username and looked for any typos. when i clicked the launcher it creates a file .restartbluetooth but nothing happens from there. and the file never gets removed... maybe the rc.local never runs?
    i tried removing the exit 0 at the end as well, both variations produce the same result


    edit: maybe i need to restart? or is there a better way getting rc.local up and running?
    Last edited by Gripp; May 1st, 2008 at 07:57 PM.

  10. #10
    Join Date
    Jun 2006
    Location
    Solihull, UK
    Beans
    1,413

    Re: Create an Icon for sudo command?

    Quote Originally Posted by ryanhaigh View Post
    A more generic version where the service and username are specified as variables

    Code:
    #!/bin/bash
    #checks for a file in user home directory and if exists restarts service
    
    SERVICE=ddclient
    USERNAME=ryanhaigh
    
    while [ 1 ]
    do
    sleep 2
    if [ -f /home/$USERNAME/.restart$SERVICE ]; then
    echo "file found restarting $SERVICE"
    /etc/init.d/$SERVICE restart && rm /home/$USERNAME/.restart$SERVICE
    else
    echo "file not found looping"
    fi
    done
    The problem with this is it only works for the one specified user unless you edit /etc/rc.local each time a user logs in (I don't know if that is an issue on the OP's machine).

    Instead of creating and checking for a ~/.restartbluetooth, i'd probably create a /tmp/.restartbluetooth. With that, you could make it work in a multi-user setup I think.

    Although, I think the OP should also try and get to the bottom of the actual problem
    Last edited by chrisccoulson; May 1st, 2008 at 09:05 PM. Reason: Actually, just googled this keyboard and it seems that connection dropping is endemic with it

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •