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:

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
6
  • The line #!/bin/bash should be the first line of the script. Check if that helps.
    – ott--
    May 22, 2016 at 16:00
  • no, it does not really matter, as it works in terminal
    – penta
    May 22, 2016 at 16:01
  • Let it run with sh -x script to see what and how the commands are executed.
    – ott--
    May 22, 2016 at 16:09
  • can you tell me more about sh -x script, i dont know that command
    – penta
    May 22, 2016 at 16:10
  • I think you just get main site html with lynk --dump but i prefer to use built in command that is wget will be more best for your purpose. Also if you have a script you have to write hashbang in the first line without white space if you dont it just act as comment. The last thing is dont forget to look for grep syntax because "slicon+valley" will match "sliconnnnnnnnnvalley" or "sliconvalley" the n letter count is not important. So it wont match the string "slicon+valley". If you grep the input as string you need to escape special charecters. So the syntax will look like this "slicon.va"
    – makgun
    May 23, 2016 at 22:18

1 Answer 1

1
    #!/bin/bash
##Sorry for bad English.
##usage: script_name.sh silicon valley
##This urlencode fonction is from github project but I couldnt remember who is creator.
urlencode() {
    # urlencode <string>

    local length="${#1}"
    for (( i = 0; i < length; i++ )); do
        local c="${1:i:1}"
        case $c in
            [a-zA-Z0-9.~_-]) printf "$c" ;;
            *) printf '%s' "$c" | xxd -p -c1 |
                   while read c; do printf '%%%s' "$c"; done ;;
        esac
    done
}
##In this case it doesnt requirement.
urldecode() {
    # urldecode <string>

    local url_encoded="${1//+/ }"
    printf '%b' "${url_encoded//%/\\x}"
}


a=$(lynx --dump "http://kat.cr/usearch/$(urlencode $@)"|grep "magnet"|sed "s/.*&dn=\([^&]*\).*/\1/g"|sed "/^$/d")
line=$(wc -l < <(echo "$a"))
echo "no. of line $line"
for i in 03 05 06 07 08 09 10;do 
    if [[ $(echo "$a"|grep "silicon.valley.s03e$i.720p.hdtv.x265.hevc") ]];then #Also you can use variable for s03 but this is just example
    echo "$a"|grep -n "silicon.valley.s03e$i.720p.hdtv.x265.hevc" #This will print like "8:silicon+valley+s03e03+720p+hdtv+x265+hevc+135mb+shaanig"
    lineno=$(echo "$a"|grep -n "silicon.valley.s03e$i.720p.hdtv.x265.hevc"|cut -d: -f1)
    link=$(echo "$a"|grep -n "silicon.valley.s03e$i.720p.hdtv.x265.hevc"|cut -d: -f2)
    #notify-send -i $HOME/Desktop/flash/Flash.ico 'Flash is Running' "Getting silicon valley episode ${i}"
    fi
done

I hope this will give you some idea for how you need to use this script. Dont hardcode for every single letter just do it in loop. Also if you do repeat a couple of command just add a function like this

function repeating_command() {
echo $@ #this will print all argument
#grep -n "$(echo "$@"|cut -d" " -f2-)" $1 #I assume that first argument is filename Other args are for searched by grep.
echo FileName is $1
echo willSearchByGrep is $(echo "$@"|cut -d" " -f2-)
}
#example usage: repeating_command FileName silicon.valley

You must log in to answer this question.

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