0

I have a script named 999_thaw_flash.sh in my /etc/pm/sleep.d

The script follows like this :-

export DISPLAY=:0
#!/bin/bash
case "{$1}" in
    resume|thaw)
lynx --dump link1 >> file1
lynx --dump link2 >> file1
lynx --dump link3 >> file1

grep "magnet:?xt=urn:btih:" file1 > file2

sed -i 's/^......//' file2

awk '/org%3A1337%2Fannounce/{print;print "";next}1' file2 >> file3

lines=$(wc -l < file3)

echo "no. of line $lines"
    if grep silicon+valley+s03e03+720p+hdtv+x265+hevc+ file3;
        then
            lineno=$(grep -n silicon+valley+s03e03+720p+hdtv+x265+hevc+ file3 | cut -d : -f 1)
            echo "current line no :-" $lineno
            link=$(head -n $lineno file3 | tail -1)
            echo $link
                notify-send -i /home/hasan/Desktop/flash/Flash.ico 'Flash is Running' 'Getting silicon valley episode 3'
                transmission-remote -a $link
                echo $link >> flush
                echo "\n\n" >> flush

    fi

    if grep silicon+valley+s03e05+720p+hdtv+x265+hevc+ file3;
        then
            lineno=$(grep -n silicon+valley+s03e05+720p+hdtv+x265+hevc+ file3 | cut -d : -f 1)
            echo "current line no :-" $lineno
            link=$(head -n $lineno file3 | tail -1)
            echo $link
                notify-send -i /home/hasan/Desktop/flash/Flash.ico 'Flash is Running' 'Getting silicon valley episode 5'
                transmission-remote -a $link
                echo $link >> flush
                echo "\n\n" >> flush
    fi

    if grep silicon+valley+s03e06+720p+hdtv+x265+hevc+ file3;
        then
            lineno=$(grep -n silicon+valley+s03e06+720p+hdtv+x265+hevc+ file3 | cut -d : -f 1)
            echo "current line no :-" $lineno
            link=$(head -n $lineno file3 | tail -1)
            echo $link
            notify-send -i /home/hasan/Desktop/flash/Flash.ico 'Flash is Running' 'Getting silicon valley episode 6'
            echo episode 6 of silicon valley online
                transmission-remote -a $link
                echo $link >> flush
                echo "\n\n" >> flush
    fi
    if grep silicon+valley+s03e07+720p+hdtv+x265+hevc+ file3;
        then
            lineno=$(grep -n silicon+valley+s03e07+720p+hdtv+x265+hevc+ file3 | cut -d : -f 1)
            echo "current line no :-" $lineno
            link=$(head -n $lineno file3 | tail -1)
            echo $link
            notify-send -i /home/hasan/Desktop/flash/Flash.ico 'Flash is Running' 'Getting silicon valley episode 7'
            echo episode 7 of silicon valley online
                transmission-remote -a $link
                echo $link >> flush
                echo "\n\n" >> flush
    fi
    if grep silicon+valley+s03e08+720p+hdtv+x265+hevc+ file3;
        then
            lineno=$(grep -n silicon+valley+s03e08+720p+hdtv+x265+hevc+ file3 | cut -d : -f 1)
            echo "current line no :-" $lineno
            link=$(head -n $lineno file3 | tail -1)
            echo $link
            notify-send -i /home/hasan/Desktop/flash/Flash.ico 'Flash is Running' 'Getting silicon valley episode 8'
            echo episode 8 of silicon valley online
                transmission-remote -a $link
                echo $link >> flush
                echo "\n\n" >> flush
    fi
    if grep silicon+valley+s03e09+720p+hdtv+x265+hevc+ file3;
        then
            lineno=$(grep -n silicon+valley+s03e09+720p+hdtv+x265+hevc+ file3 | cut -d : -f 1)
            echo "current line no :-" $lineno
            link=$(head -n $lineno file3 | tail -1)
            echo $
            notify-send -i /home/hasan/Desktop/flash/Flash.ico 'Flash is Running' 'Getting silicon valley episode 9'
            echo episode 9 of silicon valley online
                transmission-remote -a $link
                echo $link >> flush
                echo "\n\n" >> flush
    fi
    if grep silicon+valley+s03e10+720p+hdtv+x265+hevc+ file3;
        then
            lineno=$(grep -n silicon+valley+s03e10+720p+hdtv+x265+hevc+ file3 | cut -d : -f 1)
            echo "current line no :-" $lineno
            link=$(head -n $lineno file3 | tail -1)
            echo $link
            notify-send -i /home/hasan/Desktop/flash/Flash.ico 'Flash is Running' 'Getting silicon valley episode 10'
            echo episode 10 of silicon valley online
                transmission-remote -a $link
                echo $link >> flush
                echo "\n\n" >> flush
    fi
    ;;
esac    

I hope that syntax is correct and the placement of script is in correct folder.

The script does not execute on system resume.

Where am I going wrong ?

I have tried :- Run Script on Wakeup?

how to execute a command after resume from suspend?

How to run a script after the system resumes from hibernate (suspent-to-disk)?

How to run a script when suspending/resuming? - Sony VAIO Ubuntu 12.04

https://unix.stackexchange.com/questions/37892/run-a-script-after-lid-is-opened

https://superuser.com/questions/733333/how-do-i-run-commands-on-suspend-return-from-suspend

But none seem to help me.

P.S. The script runs fine on terminal.

The logs :-

May 22 20:39:16 user-550p5c-550p7c systemd-sleep[19426]: /lib/systemd/system-sleep/flush failed with error code 1.
May 22 20:39:16 user-550p5c-550p7c systemd-sleep[19426]: /lib/systemd/system-sleep/Flash.ico failed with error code 1.
May 22 20:39:16 user-550p5c-550p7c systemd-sleep[19426]: /lib/systemd/system-sleep/file3 failed with error code 1.
May 22 20:39:16 user-550p5c-550p7c systemd-sleep[19424]: Failed to connect to non-global ctrl_ifname: (nil)  error: No such file or directory
May 22 20:39:16 user-550p5c-550p7c systemd-sleep[19424]: Suspending system...
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19424]: System resumed.
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19424]: Failed to connect to non-global ctrl_ifname: (nil)  error: No such file or directory
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19459]: /lib/systemd/system-sleep/wpasupplicant failed with error code 255.
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19459]: /lib/systemd/system-sleep/Flash.ico failed with error code 1.
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19459]: /lib/systemd/system-sleep/file3 failed with error code 1.
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19459]: /lib/systemd/system-sleep/file1 failed with error code 1.
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19459]: /lib/systemd/system-sleep/file2 failed with error code 1.
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19459]: /lib/systemd/system-sleep/999_thaw_flash.sh failed with error code 1.
May 22 20:39:23 user-550p5c-550p7c systemd-sleep[19459]: /lib/systemd/system-sleep/flush failed with error code 1.
May 22 20:39:25 user-550p5c-550p7c systemd-sleep[19424]: /dev/sda:
May 22 20:39:25 user-550p5c-550p7c systemd-sleep[19424]:  setting Advanced Power Management level to 0xfe (254)
May 22 20:39:25 user-550p5c-550p7c systemd-sleep[19424]:  APM_level        = 254
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Looking up kat.cr
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Unable to locate remote host kat.cr.
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Alert!: Unable to connect to remote host.
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: lynx: Can't access startfile https://kat.cr/usearch/the%20flash/
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Looking up kat.cr
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Unable to locate remote host kat.cr.
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Alert!: Unable to connect to remote host.
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: lynx: Can't access startfile https://kat.cr/usearch/gotham/
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Looking up kat.cr
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Unable to locate remote host kat.cr.
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: Alert!: Unable to connect to remote host.
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: lynx: Can't access startfile https://kat.cr/usearch/silicon%20valley/
May 22 20:39:30 user-550p5c-550p7c systemd-sleep[19424]: no. of line 0
2
  • What version of Ubuntu ?
    – EdiD
    May 22, 2016 at 14:23
  • version is 16 lts
    – penta
    May 22, 2016 at 14:30

2 Answers 2

0

Since systemd the proper location for this is /lib/systemd/system-sleep. Make there a file eg. 999_thaw_flash and paste like this :

#!/bin/sh

case $1/$2 in
    post/suspend)
        your_srcipt_here ....
    ;;
esac
7
  • nope, didnot work
    – penta
    May 22, 2016 at 14:47
  • Did you set executable bit ?
    – EdiD
    May 22, 2016 at 14:48
  • yes i did, it was done
    – penta
    May 22, 2016 at 14:50
  • There is default hdparm file can you cat its structure and make the same with your script. I'm wondering if this will work ?
    – EdiD
    May 22, 2016 at 14:55
  • 1
    After suspend you can investigate for errors with journalctl -u systemd-suspend.service it will tell you about executing scripts after waking up
    – EdiD
    May 22, 2016 at 15:02
0

Adding this answer for anyone who still needs a solution for newer versions. I see this has been viewed many times.

I had to use a sleep/wake script to manually unmount/mount some network share folders that would hang otherwise on resume. I had a lot of trouble with setting this up, and discovered you need the "PATH=/sbin:/usr/sbin:/bin:/usr/bin" line to execute any terminal commands. You can use a basic script template like this for an example:

#!/bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin #required to execute terminal commands

case "$1" in
    pre) #sleep
            #script for executing with hibernation
    ;;
    post) #resume
            #script here for resuming
    ;;
esac

Make sure the script is executable by typing "chmod +x /path/to/script/" in terminal. Make sure root is the owner with "sudo chown root:root /path/to/script/".

Hope this helps. Running on Ubuntu 20.04 and Linux Mint 20.2.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .