# [SOLVED] ACPID laptop suspend and hibernate? (script help)

## felixculpa

Hi everyone. It's been awhile since I've had to use acpid (not since my Archbang days) but anyway my suspend setup is not working. I have the kernel options enabled, pm-utils installed, the script files chmoded with +x and I inserted the following in /etc/acpi/default.sh 

```
         lid)

            /etc/acpi/actions/lidclose.sh

            ;;
```

 right under 

```
case "$group" in

   button)

      case "$action" in

         power)

            /etc/acpi/actions/powerbtn.sh

            ;;
```

 and finally in /etc/acpi/actions/lidclose.sh is the following: 

```
#!/bin/sh

    case $3 in

        close)

             /usr/sbin/pm-suspend &

             DISPLAY=:0.0 su -c - "<my-user-name>" /usr/bin/slock;;

        open) :;;
```

 I would restart the acpid service and close the lid but nothing happens. The individual commands in the scripts work if I type them out manually. I am probably missing something obvious here as I don't really actually understand scripts, I just put this together from what I gathered elsewhere. I would like to be able to hibernate as well, and I created a swapfile and will probably be able to figure out how to invoke pm-hibernate through acpid once I find out what is wrong with the suspend script.Last edited by felixculpa on Sat Nov 08, 2014 5:56 pm; edited 1 time in total

----------

## Hu

Does your system generate an ACPI lid event when you close the lid?  Some systems use strange names or fail to generate seemingly obvious events.  I would start by setting the lid close action to be a command that leaves obvious evidence it ran, such as date >> well-known-file.  Then close the lid and check whether the current date was written.  If yes, then your problem is with the suspend commands.  If no, then your problem is that acpid is not reporting the lid closure in a way that the script recognizes or that acpid is not reporting a lid closure at all.

----------

## Yamakuzure

You are just calling your lidclose.sh without any arguments but rely on argument 3 to be "close" in the script. So it seems you are missing an "$@" there.

----------

## felixculpa

I think you are both on to something. Putting in date >> file didn't put anything into the file. I'm not sure what Yamakuzure means with the $@. In /etc/acpi/default.sh there is this: 

```
#!/bin/sh

# /etc/acpi/default.sh

# Default acpi script that takes an entry for all actions

set $*

group=${1%%/*}

action=${1#*/}

device=$2

id=$3

value=$4
```

 at the top. I assumed the scripts under the actions directory would simply be appended, in a way and read the settings in default.sh, specifically the id=$3 part? Perhaps I should just take the scripts under the actions directory and put them into default.sh?

----------

## DirtyHairy

Yamakuzure is correct.  Nothing is magically read or appended anywhere; lidclose.sh is run as a separate command in its own shell. $3 refers to the third command line argument, and as you run the script without arguments, it will always be empty. You need to call the script as 

```
lidclose.sh "$@"
```

 in order to pass the arguments of default.sh  to lidclose.sh - "$@" will be substituted with the argument list by the shell.

----------

## felixculpa

Still doesn't work, something else is obviously wrong. Here are the files:

/etc/acpi/default.sh

```
#!/bin/sh

set $*

group=${1%%/*}

action=${1#*/}

device=$2

id=$3

value=$4

log_unhandled() {

   logger "ACPI event unhandled: $*"

}

case "$group" in

   button)

      case "$action" in

         power)

            /etc/acpi/actions/powerbtn.sh ;;

         lid)

            /etc/acpi/actions/lidclose.sh $@ ;;

         *) log_unhandled $* ;;

      esac

      ;;

   ac_adapter)

      case "$value" in

         *) log_unhandled $* ;;

      esac

      ;;

   *)   log_unhandled $* ;;

esac
```

/etc/acpi/actions/lidclose.sh

```
#!/bin/sh

  case $3 in

      close)

           /usr/sbin/pm-suspend &

           DISPLAY=:0.0 su -c - <my user name> /usr/bin/slock;;

      open) :;;
```

There is probably either a syntax error or a character that either shouldn't be in there or should be something else...

----------

## palettentreter

Well first of all, in lidclose.sh, you're not closing the "case" statement. It should be:

```

#!/bin/sh

case $3 in

    close)

        /usr/sbin/pm-suspend &

          DISPLAY=:0.0 su -c - "<my-user-name>" /usr/bin/slock;;

    open) :;;

esac

```

Then try running "/etc/acpi/actions/lidclose.sh what ever close" in your shell and see if that works. If it does, you should be fine, the rest looks OK to me now.

----------

## felixculpa

YES! The missing "esac" close was what was missing. It works now, thanks for the help.

----------

