0

I found this question: How can I run a command which will survive terminal close?, which addresses exactly what I want to do. And I've been using it for a few applications.

But my problem is that I want to use terminal to run a program (OBS) with sudo (root?), because I want it to write to a mounted disk to record. So it requires write permissions that it doesn't natively have (maybe that's the issue?). And, I want to run it from a terminal, and have the terminal shut down as soon as I start the program.

I'm familiar with Linux, but I'm still super derpy at it. I know I have the drive mounted upon boot via fstab. But I if I don't run OBS with elevated rights, it gives me errors for recording.

Can I do this from the terminal and have the terminal shut down afterwards, but keep OBS open, or is this more involved?

(Using Manjaro.)

Asinine
  • 47
  • While I'm not versed enough to give you the exact answer, I can tell that what you want to look at really is the permissions, as you already suspected. Running something like OBS with root is always a (bad) workaround. There are ways to mount a drive so that a user can write to it. Check out some related questions. Also, have you thought about using something like dmenu (or similar application starter)? – domsson Dec 08 '19 at 05:10
  • If I remember correctly, you should be able to fix the permission issues by (a) mounting the drive somewhere in your regular user's home dir (/home/asinine/mount, for example), (b) using the rw, user and uid/gid options in the fstab mount command (possibly also umask=000 if this is an ntfs drive). – domsson Dec 08 '19 at 05:21
  • I am confused: Do you want to close terminal after (as in title, and paragraph 2), or to have the command continue after terminal closes (paragraph 1)? Please edit question to make this clear. – ctrl-alt-delor Dec 08 '19 at 07:16
  • You don't need to be root to write to a device: That is what file permissions are for. Change the file permissions (ownership / mode / etc). You will need elevated capabilities to do this (e.g. sudo to root). – ctrl-alt-delor Dec 08 '19 at 07:18
  • Indeed, running a program as root for a sole purpose of write permissions is bad. With linux file systems you can modify permissions, ownership or - if the filesystem supports them - ACLs. For other file systems you can set permissions during mount or assign them to the mount directory. You may run the command as a user with permissions limited to running the program and to its working directory. Running as root should be the very last on the list.

    Also, it's not very clear if you want to have the window closed as soon as the program is run in the background, or as soon as it terminates.

    – Jasio Dec 08 '19 at 10:04
  • @ctrl-alt-delor I want the terminal to close, not the program that was run from terminal (which I do think is clearly stated in the first paragraph with the link I have posted; please correct me if I am wrong). I have been using things like "obs & exit" which works fine. I will attempt domsson's (sorry, can only notify one user at a time) advice, as I am horribly unknowledgable about permissions. The drive mounts properly upon boot (via fstab), so I will proceed from there. Thank you all for your input. – Asinine Dec 08 '19 at 23:21
  • OK. So the problem is in the title, and paragraph 2. Run a command and close terminal after. (I did not say that the error was in paragraph 1. I only said that it is inconsistent with paragraph 2 and the title). Thank you for telling me which bit needs fixing. This time I did it for you. – ctrl-alt-delor Dec 09 '19 at 17:06
  • Sudo is pretty explicitly interactive in most configurations so i'm guessing this may not work as well as you'd like since it's not really scriptable. – davolfman Dec 10 '19 at 22:42

2 Answers2

2

This should do it.

command & disown; exit

The & puts it in the background. The disown tells the shell to not job control it. The exit tells the shell to exit.

You can put it in an alias, to make it easier to use. e.g. (for a different program)

alias mon="ksysguard& disown; exit"

Put the alias in ~/.bashrc

However I think this is an XY problem: you are trying to solve the wrong problem.

  • After your (plural) comments and this explanation (and the XY reference), I believe this is the correct way to solve the problem I thought I had. But as it was pointed out, it was a permissions problem. I think I figured that out, as obs now runs and records (because I allowed it access to the separate hard drive), and I can use my plain original obs & exit without necessitating sudo. – Asinine Dec 10 '19 at 22:21
1

Another approach can be use the nohup command, that is delegated to run a command in backround and write the result to a file.

alessiosavi
  • 347
  • 2
  • 9
  • I had actually been looking into nohup, but all I seemed to accomplish with it was having a log file, for reasons I don't understand. I did get it working (with sudo, while trying to figure this out before posting here), but I don't understand why I'd want the log file attached to the process. I'd think might as well just have another window open, since at least that isn't writing logs I don't need? – Asinine Dec 10 '19 at 22:25
  • You can append & to the command in order to run the process in background, and you can redirect the output to /dev/null in order to discard the log – alessiosavi Dec 11 '19 at 09:27