小编use*_*335的帖子

通知发送在 crontab 中不起作用

我制作了一个脚本,当我正在阅读漫画的新章节时,它会通知我。我使用命令 notify-send 来做到这一点。当我尝试在终端中运行该程序时,该程序有效。通知显示。但是,当我把它放在我的 crontab 中时,通知没有显示。我很确定该程序正在运行,因为我为我创建了一个文件。文件已创建,但未显示通知。

这是我的脚本

#!/bin/bash   
#One Piece Manga reminder    
#I created a file named .newop that contains the latest chapter.    
let new=$(cat ~/.newop)    
wget --read-timeout=30 -t20 -O .opreminder.txt http://www.mangareader.net/103/one-piece.html

if (( $(cat .opreminder.txt | grep "One Piece $new" | wc -l) >=1 ))    
then    
    (( new+=1 ))    
    echo $new    
    echo $new > ~/.newop    
    notify-send "A new chapter of One Piece was released."    
else    
    notify-send "No new chapter for One Piece."    
    notify-send "The latest chapter is still $new."    
fi …
Run Code Online (Sandbox Code Playgroud)

cron notify-send

58
推荐指数
6
解决办法
4万
查看次数

输入密码时如何使用退格字符作为退格?

我刚刚在某处看到了这段代码。
它允许用户输入他的密码并将其更改为星号/星号。
但它无法识别退格键。
代码认为退格键是密码的一部分。
我该怎么做才能让它识别退格键?
有人可以向我解释这段代码吗?
尤其是 IFS、读取选项和 $'\0'
谢谢!

这是代码。

\#!/bin/bash
unset password
prompt="Enter Password:"
while IFS= read -p "$prompt" -r -s -n 1 char
do
if [[ $char == $'\0' ]]
then
    break
fi
prompt='*'
password+="$char"
done
echo
echo "Done. Password=$password"
Run Code Online (Sandbox Code Playgroud)

bash password

3
推荐指数
1
解决办法
6328
查看次数

标签 统计

bash ×1

cron ×1

notify-send ×1

password ×1