You are not logged in.

#1 2023-01-15 20:50:02

Daerun
Member
Registered: 2011-02-07
Posts: 92

Making systemd service to open terminal

I have little idea of scripting, but I came up with this systemd service that calls for a backup script every time I plug the external usb drive:

[Unit]
Description=Backup
Requires=my_usb_hdd.mount
After=my_usb_hdd.mount

[Service]
ExecStart=/home/daerun/Scripts/backup.sh

[Install]
WantedBy=my_usb_hdd.mount

This works fine; BUT I would like it to actually open a terminal to run the backup script so I can see it, how could I achieve this?

Offline

#2 2023-01-15 21:01:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,802
Website

Re: Making systemd service to open terminal

The direct answer is that it would have to be a systemd user service and you'd have to properly import the environment for your graphical session so you could launch a terminal emulator running the script (e.g., "ExecStart=/bin/urxvt -c /home/daerun/Scripts/backup.sh'").

However, that's probably not what you really want to do.  Why do you (think you) want to "see it"?  Do you just want to check for errors?  Why not have the script log relevant information somewhere you can check?


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2023-01-17 01:12:15

Daerun
Member
Registered: 2011-02-07
Posts: 92

Re: Making systemd service to open terminal

Trilby wrote:

The direct answer is that it would have to be a systemd user service and you'd have to properly import the environment for your graphical session so you could launch a terminal emulator running the script (e.g., "ExecStart=/bin/urxvt -c /home/daerun/Scripts/backup.sh'").

However, that's probably not what you really want to do.  Why do you (think you) want to "see it"?  Do you just want to check for errors?  Why not have the script log relevant information somewhere you can check?

Both answers seem ok to me. Will try the first option ASAP. As for the second, how could it be done?

Edit: I googled a bit, but as I said I am quite illiterate in scripting as of now, but have seen code lines of the like of:

/bin/sh -x /my/script/file 2>/my/log/file

or this

#!/bin/bash
(
  blah code
) 2>&1 | tee -a file.log

Last edited by Daerun (2023-01-17 01:17:09)

Offline

#4 2023-01-17 01:24:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 27,802
Website

Re: Making systemd service to open terminal

If you want to know how to make your script generate useful logging information you'd have to show, or at very least describe, the script.

Strictly speaking, you could do something like the first example and just make the systemd service file log the output to a file.  But systemd already logs all the output to the journal.  As this is your own script, though, it'd make more sense to do the logging from within the script: hence knowing what the script actually does is essential.

Last edited by Trilby (2023-01-17 01:25:59)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB