Help to run a script before login

Hi i am very noob. Need to autostart a script like wakeonlan -i IP xx.xx.xx.xx mac xx:xx:xx:xx.
the script .sh work fine but only AFTER login (i put him in autostart)

Also i try to put him on /etc/X11/xinit/xinitrc.d/ but also run after login…

Can you help?

Thx!

You should create a system service that starts with your computer in that case.
See the results of a search-engine for more details about systemd-services:

ok, read guideline but not working :smile:

first created monitoron.script on /etc/systemd/system - command on konsole work good

monitoron.script:
[Unit]
Description=Wake-on-LAN
Requires=network.target
After=network.target

[Service]
ExecStart=/home/cesare/.local/bin/wakeonlan -i IP XX.XX.XX.XX MAC XX:XX:XX:XX
Type=oneshot

[Install]
WantedBy=multi-user.target

Last enabled script
systemctl enable monitoron.service

What is wrong?
thx

? monitoron.service file and not monitoron.script

systemctl enable

service is ok only after reboot …

We can test service by sudo systemctl start monitoron (and we can read result in journalctl)

service tested, powered off monitor and launched test systemctl “start monitoron.service”, work.

it work as a test, but when reboot or power off/on won’t work :upside_down_face:

journal

|---|---|---|
|19/02/23 22:39|kernel|audit: type=1131 audit(1676842796.473:134): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|```

Edit i get somepoint...

journal after startup fail but adding "Restart=on-failure & RestartSec=3" willl work! 


```  |19/02/23 23:17|systemd|monitoron.service: Main process exited, code=exited, status=1/FAILURE|
|---|---|---|
|19/02/23 23:17|systemd|monitoron.service: Failed with result 'exit-code'.|
|19/02/23 23:17|audit|SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=failed'|
|19/02/23 23:17|systemd|monitoron.service: Scheduled restart job, restart counter is at 1.|
|19/02/23 23:17|audit|SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|audit|SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|systemd|monitoron.service: Main process exited, code=exited, status=1/FAILURE|
|19/02/23 23:17|systemd|monitoron.service: Failed with result 'exit-code'.|
|19/02/23 23:17|audit|SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=failed'|
|19/02/23 23:17|systemd|monitoron.service: Scheduled restart job, restart counter is at 2.|
|19/02/23 23:17|audit|SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|audit|SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|kernel|audit: type=1130 audit(1676845042.526:70): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|kernel|audit: type=1131 audit(1676845042.526:71): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|systemd|monitoron.service: Deactivated successfully.|
|19/02/23 23:17|audit|SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|audit|SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|kernel|audit: type=1130 audit(1676845042.553:72): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'|
|19/02/23 23:17|kernel|audit: type=1131 audit(1676845042.553:73): pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=monitoron comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'| ```

You probably need network-online.target see: systemd.special

PS: To check logs for the unit you can use one of the below or both:

  1. systemctl status monitoron
  2. journalctl -u monitoron

  • Please edit your post with output so the log outputs are placed between codeblocks as:
    ```
    text
    ```
    Those are backticks normally found on the left of the 1 on your keyboard…
1 Like

Solved! now monitor power on at login!!! :smiley:

using this service:

[Unit]
Description=Wake-on-LAN
Requires=network-online.target
After=network-online.target

[Service]
ExecStart=/home/userxxx/.local/bin/wakeonlan -i XXX.XXX.X.XX(IP) XX:XX:XX:XX:XX:XX(MAC)
Type=oneshot

[Install]
WantedBy=multi-user.target
WantedBy=network-online.target

Now i try to make a service turning off monitor when system suspend:

[Unit]
Description=off screen before suspend
Requires=network-online.target
Before=network-online.target
Before=suspend.target sleep.target

[Service]
ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/lgtv MyTv off ssl
Type=oneshot

[Install]
WantedBy=suspend.target sleep.target
WantedBy=network-online.target

This script WORK if i test him, but suspending manjaro make lan disconnected IMMEDIATLY (red X on lan icon) i use sleep 5 to see what’s happening while service running:

  • click suspend
  • lan disconnect immediatly
  • remote command error beaucause lan is disconnected
  • 5 seconds pass
  • system will suspend

My question: there is a way to tell at service “don’t stop ethernet when suspend?” Or configure lan to NOT disable when suspend system? Modify suspend rules?

Thx

In your monitoron service:

This is wrong, because that is used for services that setup your network config for your own machine…
So you should disable your service again, then remove that line and re-enable the service again.
(If not done this way the link will not be removed)

With respect to your second problem/question about suspend/resume, it is better to create a new thread about that to keep this thread clean for the Title it has for other readers in future…
Because That is a totally different topic which has completely different stuff involved…

Ok, solved! WantedBy=network-online.target is wrong but it work. I removed the line and now the script it’s better Thx!!!