Results 1 to 10 of 10

Thread: [SOLVED] [bash]: Work around it- Slow shutdown

  1. #1
    Join Date
    Apr 2008
    Location
    Denmark
    Beans
    219
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Question [SOLVED] [bash]: Work around it- Slow shutdown

    Lady and gentlemen,


    I have a little issues w. Ubuntu after discarding my initial 7.10 install. When I click the "Shutdown" icons, the system (input/output) seems to freeze completely for about 3 - 5 minutes, whereafter the shutdown dialog will appear and I can shut down. After doing much reading I find that this is usually because of an incorrectly configured loopback device - this doesn't seem to be that case here, as it looks correctly configured. (anybody know of a test for this?).

    So, to work around this issue, I wanted to make a little script which did a "sudo shutdown -P now", and simple type "bye" in the terminal to shutdown. But how do I form the script if I want to automatically feed the sudo-password to the command? I've tried something like echo "topsycrets" | sudo shutdown", but it doesnt do the trick.

    Any suggestions for either loopback or bash workaround?

    /Lau
    "“For everyone who asks receives, and he who seeks finds, and to him who knocks it will be opened."

  2. #2
    Join Date
    Oct 2007
    Location
    Athens, Greece
    Beans
    179
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: [bash]: Work around it- Slow shutdown

    If you want, you can shutdown your pc, without typing any password...
    Just edit your /etc/sudoers file:
    Code:
    sudo visudo
    Then, add the following line:
    Code:
    %<your usename> ALL=(ALL) NOPASSWD: sudo shutdown -P now
    (or any other command you want).
    Hope this helps!
    Beware of he who would deny you access to information, for in his heart he dreams himself your master.

  3. #3
    Join Date
    Apr 2008
    Location
    Denmark
    Beans
    219
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: [bash]: Work around it- Slow shutdown

    Quote Originally Posted by Thanoulis View Post
    If you want, you can shutdown your pc, without typing any password...
    Just edit your /etc/sudoers file:
    Code:
    sudo visudo
    Then, add the following line:
    Code:
    %<your usename> ALL=(ALL) NOPASSWD: sudo shutdown -P now
    (or any other command you want).
    Hope this helps!
    It seemed like a good idea at the time!

    After appending that line to the /etc/sudoers, sudo has stopped working. It says ">>>> sudoers file: syntax error, line 23 <<<<" - How do I recover from this? I cant even edit the file with the rights I have now.

    /Lau
    "“For everyone who asks receives, and he who seeks finds, and to him who knocks it will be opened."

  4. #4
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [bash]: Work around it- Slow shutdown

    1. Boot into recovery mode and run visudo, or
    2. Boot the liveCD, mount your / to /media/disk or wherever, and run
    Code:
    sudo chroot /media/disk
    Then, inside chroot, run visudo.

    The reason it didn't work, is because the syntax is wrong. The first field should be either "%<group>" or "<username>" (without %). You should read the manpage for sudoers for a full doc,
    Code:
    man sudoers

  5. #5
    Join Date
    Apr 2008
    Location
    Denmark
    Beans
    219
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: [bash]: Work around it- Slow shutdown

    Quote Originally Posted by geirha View Post
    1. Boot into recovery mode and run visudo, or
    2. Boot the liveCD, mount your / to /media/disk or wherever, and run
    Code:
    sudo chroot /media/disk
    Then, inside chroot, run visudo.

    The reason it didn't work, is because the syntax is wrong. The first field should be either "%<group>" or "<username>" (without %). You should read the manpage for sudoers for a full doc,
    Code:
    man sudoers
    Alright - I was hoping there was a way around booting (lazy I know), but at least it will work - I hope. I'll let you know on the other side.

    Thanks for the explanation of the sudoers file.

    /Lau
    "“For everyone who asks receives, and he who seeks finds, and to him who knocks it will be opened."

  6. #6
    Join Date
    Apr 2008
    Location
    Denmark
    Beans
    219
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: [bash]: Work around it- Slow shutdown

    I tried replacing the % with nothing, so just the username, it didnt work. Then I tried "username ALL=NOPASSWD: sudo shutdown -P", and that didnt work either, but at least I have sudo rights again.

    Can anybody tell me the correct syntax for giving me sudo access to shutdown -P now, w/o entering the password?

    /Lau
    "“For everyone who asks receives, and he who seeks finds, and to him who knocks it will be opened."

  7. #7
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [bash]: Work around it- Slow shutdown

    Oops, didn't notice that earlier, but you shouldn't have sudo in there
    Code:
    username ALL=NOPASSWD: sudo shutdown -P now
    That would produce an infinite loop, since it reads /etc/sudoers each time you run sudo ...
    Code:
    username ALL = NOPASSWD: shutdown -P now
    really should work.

    Also, note that the position in the file is important. From the man-page of sudoers:
    Code:
           When multiple entries match for a user, they are applied in order.
           Where there are multiple matches, the last match is used (which is not
           necessarily the most specific match).
    Last edited by geirha; May 29th, 2008 at 02:35 PM.

  8. #8
    Join Date
    Apr 2008
    Location
    Denmark
    Beans
    219
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: [bash]: Work around it- Slow shutdown

    Its really weird!

    I tried
    Code:
    username<tab>ALL=NOPASSWD: shutdown -P now
    username<space>ALL=NOPASSWD: shutdown -P now
    username<tab>ALL<space>=<space>ALL=NOPASSWD: shutdown -P now
    username<space>ALL=(ALL)<space>ALL=NOPASSWD: shutdown -P now
    ...and so on.. every single combination gives me a parse error...

    /Lau
    "“For everyone who asks receives, and he who seeks finds, and to him who knocks it will be opened."

  9. #9
    Join Date
    Feb 2007
    Beans
    4,045
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: [bash]: Work around it- Slow shutdown

    It's been a while since I messed around with sudoers, but I think I found it now. The command needs to be represented with an absolute path (which is obvious when you think of security). So
    Code:
    username ALL=NOPASSWD: /sbin/shutdown -P now
    Hopefully that's the final change to the original line

    And remember it needs to be before the general
    Code:
    %admin ALL=(ALL) ALL
    line.

    EDIT: No wait, I've misread the man-page, it should be after the %admin ALL...-line
    Last edited by geirha; May 29th, 2008 at 03:33 PM.

  10. #10
    Join Date
    Apr 2008
    Location
    Denmark
    Beans
    219
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: [bash]: Work around it- Slow shutdown

    Alright, so to sum if this awful thread

    Code:
    username ALL=NOPASSWD: /sbin/shutdown -P now
    Actually works - So thanks alot for all the help!!

    To Thanoulis: Dont feel bad, even the best of us make mistakes and I thank you for trying.

    /Lau
    "“For everyone who asks receives, and he who seeks finds, and to him who knocks it will be opened."

Tags for this Thread

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
  •