Results 1 to 6 of 6

Thread: Running script from Launcher asks for password

  1. #1
    Join Date
    Dec 2013
    Beans
    27

    Running script from Launcher asks for password

    I have a script that sends the PC to sleep and wakes on the 1st of the month:

    Code:
    #!/bin/bash
    
    #current system time and waketime
    old=`date '+%H:%M'`
    new=11:55
    
    
    THISYEAR=`date +'%Y' -d 'now'`
    NEXTMONTH=`date +'%m' -d 'next month'`
    
    
    #if next month is January, increment the year by 1
    if [ $NEXTMONTH == 01 ]
    then
        THISYEAR=`date +'%Y' -d '1 year'`
    fi
    
    
    #current system date and wake date(1st of next month)
    olddate=`date +%Y-%m-%d`
    newdate=$THISYEAR"-"$NEXTMONTH"-01"
    
    
    IFS=: read old_hour old_min <<< "$old"
    IFS=: read hour min <<< "$new"
    
    
    # convert the date in seconds from Unix EPOCH time
    sec_old=$(date -d "$olddate $old_hour:$old_min:00" +%s)
    sec_new=$(date -d "$newdate $hour:$min:00" +%s)
    
    
    DIFFERENCE=$(( (sec_new - sec_old) )) 
    
    
    #lock the screen
    #gnome-screensaver-command -l
    
    
    #suspend the system and wake in this many seconds
    sudo rtcwake -m mem  -s $DIFFERENCE
    This is saved as /home/steve/SuspendWake.sh

    From the terminal, if I type

    Code:
     /home/steve/SuspendWake.sh
    the script runs as expected.

    I have created a desktop launcher to run the script above but it asks me for a password. If I change the desktop launcher command to
    Code:
    sudo /home/steve/SuspendWake.sh
    it still asks for a password, as does:
    Code:
    gksudo /home/steve/SuspendWake.sh
    I have tried adding to visudo as follows:

    Code:
    Steve ALL= NOPASSWD: /home/Steve/SuspendWake.sh
    but still no luck!

    Can anyone help getting the launcher to run without asking for a password?
    Thanks

  2. #2

    Re: Running script from Launcher asks for password

    Post your orig. .desktop, the one without (gk)sudo
    Do you care if it runs in a terminal and or does it have to run in a terminal?

    from the terminal, if I type

    /home/steve/SuspendWake.sh

    the script runs as expected.
    Is that in a new terminal? (never used to auth in.
    Last edited by mc4man; January 10th, 2014 at 01:02 AM.

  3. #3
    Join Date
    Dec 2013
    Beans
    27

    Re: Running script from Launcher asks for password

    Hi,
    Config file from home/steve/desktop/Standby.desktop:

    Code:
    [Desktop Entry]Name=Standby
    Exec=/home/steve/SuspendWake.sh
    Terminal=true
    Type=Application
    Name[en_GB]=Standby
    Icon=/home/steve/Pictures/Icons/Shutdown.png
    I have also tried the above with
    Code:
    Exec=sudo /home/steve/SuspendWake.sh
    which also asks for a password

    Is that in a new terminal? (never used to auth in.
    If I open a new terminal, and type
    Code:
    /home/steve/SuspendWake.sh
    it asks for the password. If the terminal is still running, it doesn't
    Last edited by steveearle86; January 11th, 2014 at 06:17 PM.

  4. #4

    Re: Running script from Launcher asks for password

    It seems that you're using sudo on rtcwake, not your script (SuspendWake.sh
    Does rtcwake need to be run as root?

    Does this need to be run in a terminal?, if so the add a line to .desktop
    Terminal=true

  5. #5
    Join Date
    Dec 2013
    Beans
    27

    Re: Running script from Launcher asks for password

    I see what you mean, its the RTCwake in the script asking for the password. If I change the last lines of the script to
    Code:
    #suspend the system and wake in this many seconds
    rtcwake -m mem  -s $DIFFERENCE
    (removing the sudo) and run the script from a terminal, I get
    open failed: /dev/rtc0: Permission denied
    The launcher with the command
    Code:
    Exec=/home/steve/SuspendWake.sh

    now just pops open a terminal window and shuts it immediately, I assume it is showing the same message
    Last edited by steveearle86; January 11th, 2014 at 07:38 PM.

  6. #6
    Join Date
    Dec 2013
    Beans
    27

    Re: Running script from Launcher asks for password

    Sorted!
    Run the following two commands from Terminal:

    Code:
    sudo chown steve /dev/rtc0
    Code:
    sudo chown steve /sys/power/state

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
  •