Results 1 to 1 of 1

Thread: User sleep and resume scripts

  1. #1
    Join Date
    Nov 2007
    Beans
    75

    User sleep and resume scripts

    I created a simple script to allow users to have sleep and resume scripts for laptops and such

    /usr/lib/pm-utils/sleep.d/00user_scripts
    Code:
    #!/bin/bash
    
    homes=`ls -l /home| awk '{print $3 ":/home/" $8 }'|sort|uniq`
    
    run_script()
    {
    lines=`echo -e "${homes}"|wc -l`
    x=1
    while [ $x -lt $lines ]; do
    let x=$x+1
    home=`echo -e "${homes}"|head -n $x|tail -n 1|cut -d: -f2`
    user=`echo -e "${homes}"|head -n $x|tail -n 1|cut -d: -f1`
    script=${home}/$1
    if [ -x ${script} ];then
    su ${user} -c ${script}
    fi
    done
    unset home
    unset user
    unset script
    }
    
    on_sleep()
    {
    run_script .sleep
    }
    
    on_resume()
    {
    run_script .resume
    }
    
    case $1 in
        hibernate|suspend|sleep)
            on_sleep
            ;;
        thaw|resume)
            on_resume
            ;;
        *) exit $NA
            ;;
    esac
    then any user can create a .sleep script in their home directory to run commands when the laptop is put to sleep and a .resume script in their home directory to run commands when the laptop is wakened back up. I use this to do an sshfs mount and unmount.
    Last edited by jeff.sadowski; November 18th, 2012 at 01:07 AM. Reason: my particular script needed ran at 00 not 01

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
  •