我没有使用服务截取屏幕截图

我没有使用服务截取屏幕截图

我正在使用 shell 脚本,我想在系统启动时自动运行该脚本开启/重启无需打开任何应用程序。

这是我的script.sh文件:

while sleep 5 
do
scrot 'myimage.png' -e 'mv $f ~/Desktop/'
done

测试.service文件:

[Unit]
Description=My Shell Script
   
[Service]
ExecStart=/home/chirag/tracker-ror/script.sh
    
[Install]
WantedBy=multi-user.target
> sudo systemctl status test.service

    ● test.service - My Shell Script
         Loaded: loaded (/etc/systemd/system/test.service; enabled; vendor preset: enabled)
         Active: active (running) since Sun 2022-10-02 00:40:06 IST; 53s ago
       Main PID: 841 (script.sh)
          Tasks: 2 (limit: 18399)
         Memory: 2.1M
         CGroup: /system.slice/test.service
                 ├─  841 bin/bash /home/chirag/tracker-ror/script.sh
                 └─35186 scrot myimage.png -e mv $f ~/Desktop/

出现以下错误:

    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35166]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35168]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35170]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35172]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35174]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35176]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35178]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35181]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35184]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35186]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35188]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35190]: Can't open X display. It *is* running, yeah?
    Oct 02 00:40:59 chirag-ThinkPad-T460 script.sh[35192]: Can't open X display. It *is* running, yeah?

相关内容