【发布时间】:2020-02-26 17:49:33
【问题描述】:
我有一个小问题。我正在用 systemd 做一个服务(守护进程)。脚本如下:
if [ $intento = 5 ];then
iptables -I INPUT -s ${sublista[0]} -j DROP -m comment --comment "IP bloqueada por sshield"
date=$(date)
echo "${sublista[0]} $date" >> /var/cache/sshield.deny
zenity --notification --text "IP address ${sublista[0]} denied at $date - sshield"
email ivanherediaplanas@hotmail.com "Nueva regla iptables | ${sublista[0]} denied" "The ${sublista[0]} ip address is denied by brute force's attack ssh.<br><br>Date: $date"
declare -a ips=(${ips[@]/${sublista[0]}=>$intento/})
fi
思路如下:
如果尝试超过五次,它会给出 IP 地址并锁定它。发送邮件并显示 zenity 的弹出窗口
问题是,弹出窗口没有显示。
zenity --notification --text "IP 地址 ${sublista[0]} 在 $date 被拒绝 - sshield"
我相信这是因为,scrpt 是由 /lib/systemd/system/sshield.service 中的服务文件执行的
[Unit]
Description=Service for protect attacks of brute force ssh's
[Service]
Type=simple
ExecStart=/etc/sshield/sshield.sh
ExecStop=/etc/sshield/sshield.sh stop
RemainAfterExit=yes
Restart=always
[Install]
WantedBy=multi-user.target
我认为问题出在:Type=simple
另外,我试试这个:
echo "${sublista[0]} $date" >> /var/cache/sshield.deny
sshield --bell "IP address ${sublista[0]} denied at $date - sshield"
email ivanherediaplanas@hotmail.com "Nueva regla iptables | ${sublista[0]} denied" "The ${sublista[0]} ip address is denied by brute force's attack ssh.<br><br>Date: $date"
sshield --bell "IP 地址 ${sublista[0]} 在 $date 被拒绝 - sshield"
命令sshield 是路径/bin/sshield 中的一个脚本,我会遵循它:
elif [[ $argumento == "--bell" ]];then
if [[ $# -gt 3 ]];then
echo -e "\033[1;31m[-]\033[0m Only one value"
echo "You use '--help' or '-h' for more information"
elif [[ $# = 1 ]];then
echo -e "\033[1;31m[-]\033[0m It needs one value"
echo "You use '--help' or '-h' for more information"
else
zenity --notification --text "$2"
fi
else
[...]
标记:zenity --notification --text "$2"
但是,它不起作用。我该如何解决?
错误在于zenity: image: journalctl -u sshield
【问题讨论】:
-
请检查错误日志。它可能不知道要显示在哪个显示器上,因为您在 UI 之外运行它。
-
什么错误日志?
-
查看单个systemd服务的日志,可以使用
journalctl -u sshield -
zenity --notification --text "Whatever"在终端中运行时的输出是什么? -
输出
zenity --notification --text "whatever" show a popup with the text specified。它可以工作,但在服务中不行。
标签: linux bash service systemd