999_thaw_flash.sh
我有一个名为我的脚本/etc/pm/sleep.d
脚本如下:-
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
我希望语法正确并且脚本放置在正确的文件夹中。
系统恢复时不会执行该脚本。
我哪里错了?
我努力了 :-唤醒时运行脚本?
系统从休眠状态(suspent-to-disk)恢复后如何运行脚本?
如何在暂停/恢复时运行脚本? - 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
但似乎没有什么能帮助我。
PS 该脚本在终端上运行良好。
日志:-
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
答案1
由于systemd
正确的位置是/lib/systemd/system-sleep
。在那里创建一个文件,例如,999_thaw_flash
并像这样粘贴:
#!/bin/sh
case $1/$2 in
post/suspend)
your_srcipt_here ....
;;
esac
答案2
为仍然需要新版本解决方案的任何人添加此答案。我看到这个已经被查看了很多次了。
我不得不使用睡眠/唤醒脚本来手动卸载/挂载一些网络共享文件夹,否则这些文件夹在恢复时会挂起。我在设置它时遇到了很多麻烦,发现您需要“PATH=/sbin:/usr/sbin:/bin:/usr/bin”行来执行任何终端命令。您可以使用这样的基本脚本模板作为示例:
#!/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
在终端中输入“chmod +x /path/to/script/”以确保脚本可执行。使用“sudo chown root:root /path/to/script/”确保 root 是所有者。
希望这有帮助。在 Ubuntu 20.04 和 Linux Mint 20.2 上运行。