mersenneforum.org

mersenneforum.org (https://www.mersenneforum.org/index.php)
-   Linux (https://www.mersenneforum.org/forumdisplay.php?f=39)
-   -   Debian Buster Start Script at Boot (https://www.mersenneforum.org/showthread.php?t=27985)

EdH 2022-07-31 13:58

Debian Buster Start Script at Boot
 
I've been lots of places on the web and tried both cron and creating a service in multiple manners, all without success. Can someone point me toward a procedure that works?

I basically would like a terminal to visibly run a bash script when the computer is powered up.

paulunderwood 2022-07-31 18:51

I think you need to use [C]screen[/C] as a [C]@reboo[/C]t cron job.

Details somebody please.

EdH 2022-07-31 19:41

[QUOTE=paulunderwood;610565]I think you need to use [C]screen[/C] as a [C]@reboo[/C]t cron job.

Details somebody please.[/QUOTE]My trouble with crontab was (and still is) that @reboot does absolutely nothing. No matter what I try to have happen @reboot doesn't run.*

Thanks for a new idea, though! I shall explore using a service with tmux first, since I'm already using that regularly and somewhere I read that screen is deprecated, at least in some linux packages.

* I read somewhere that having both cron and anacron could cause this, but I have only cron.

pepi37 2022-07-31 21:22

I make command (example)
[QUOTE]cd root
cd GFN1
sh 1
[/QUOTE]lets say that command is named a.sh and would like to start when machine is up/rebooted
in crontab I add line (crontab -e)
[QUOTE]@reboot a.sh[/QUOTE]put cursor in new line, save it.
On exit crontab write new job added ( or something like that)


Now I see this is not what you need :(

axn 2022-08-01 05:10

[QUOTE=EdH;610566]My trouble with crontab was (and still is) that @reboot does absolutely nothing. No matter what I try to have happen @reboot doesn't run.*[/QUOTE]

Do you use [C]sudo crontab[/C] for @reboot? I have it, and it works fine.

chris2be8 2022-08-01 16:18

Do you mean *before* or *after* you log on to the computer?
What ID should the script run as?
What terminal emulator are you using?

To run as yourself after logging on call it from .bashrc (or .profile). I've not tested this but [c]qterminal -e myscript.sh &[/c] should start myscript.sh running in a terminal (this assumes you have qterminal installed). Check the man page for whatever terminal emulator you have for other options. You might need nohup to keep it running after .bashrc has ended.

I've no idea how to get a script running in a window before you log on though. I don't think the GUI would be set up to show multiple windows then.

EdH 2022-08-01 17:00

To answer some questions:

Although I am using the root crontab to shut the machine down in the evening, I was attempting this with the user's crontab. I didn't consider trying @reboot in the root crontab. I will explore that.

My preference would be gnome-terminal, which I use everywhere across all my machines, but I only have three Debian systems and they already have some different things from the rest, so an alternate terminal wouldn't be too bad. But, I don't think the terminal choice has any bearing on the issue at hand, does it?

I'm trying to get a script to run when the system powers up and the math userid becomes active, with a visible terminal existing in the GUI when I bring it up remotely via an SSH VNC session, since these machines are headless. I do have a script that runs a gnome-terminal that in turn runs the script I'm ultimately interested in. The issue is just getting it to run when it is powered up.

From what I've read, systemd is the current preferred method to add startup scripts, and that would be fine, if it would work, but none of the examples do. I also wouldn't mind using crontab, if that would work on powerup.

As a last thought, many of the pages I've used for my trials change file attributes via chmod calls, including some making the scripts executable, while others do not. Maybe within all my play, I have those attributes all confused and really need to start fresh by deleting a bunch of things first.

Thanks everyone for trying to help me iron this out.

paulunderwood 2022-08-02 11:26

[QUOTE=EdH;610624]

I'm trying to get a script to run when the system powers up and the math userid becomes active, with a visible terminal existing in the GUI when I bring it up remotely via an SSH VNC session, since these machines are headless. I do have a script that runs a gnome-terminal that in turn runs the script I'm ultimately interested in. The issue is just getting it to run when it is powered up.

[/QUOTE]

I see this as two problems: Firstly getting something to run at boot and secondly getting something to run when logging in.

For the first use [C]@reboot su math-user -c "X"[/C] (in [C]sudo crontab -e[/C]) where X is uses the [C]screen[/C] command to run your program.

Secondly, use the [C]xterm[/C] command (or whatever) with the [C]screen[/C] command again to see the status of your process. This command string can be put into your [C].bashrc[/C] file on the target machine.

EdH 2022-08-03 19:29

[QUOTE=paulunderwood;610679]I see this as two problems: Firstly getting something to run at boot and secondly getting something to run when logging in.

For the first use [C]@reboot su math-user -c "X"[/C] (in [C]sudo crontab -e[/C]) where X is uses the [C]screen[/C] command to run your program.

Secondly, use the [C]xterm[/C] command (or whatever) with the [C]screen[/C] command again to see the status of your process. This command string can be put into your [C].bashrc[/C] file on the target machine.[/QUOTE]I tried all kinds of variations in the root crontab file, with no success. I did have success in making sure @reboot does something by having it create a file. (I didn't try that in the user crontab yet.) I did install screen since that's where everyone is pointing me. Both screen and tmux run using the command I'm adding to the root crontab, but neither work from @reboot.

As to the second, I'm not familiar with .bashrc, but doesn't that just affect the behavior of bash when run? I'm guessing the first needs to work before the second is useful.

paulunderwood 2022-08-03 22:31

[QUOTE=EdH;610745]I tried all kinds of variations in the root crontab file, with no success. I did have success in making sure @reboot does something by having it create a file. (I didn't try that in the user crontab yet.) I did install screen since that's where everyone is pointing me. Both screen and tmux run using the command I'm adding to the root crontab, but neither work from @reboot.

As to the second, I'm not familiar with .bashrc, but doesn't that just affect the behavior of bash when run? I'm guessing the first needs to work before the second is useful.[/QUOTE]

I have never used screen before and am just playing around with it now. It seems you want [C]sudo crontab -e[/C] (or root's account) and enter there [C]@reboot su math-user -c "cd /your/path && screen your_program &"[/C]. The ampersand is very important!

Then when you log in or call up a terminal type [C]screen -ls[/C] followed by [C]screen -d xxxx[/C] and [C]screen -r xxxx[/C] where xxxx is the number given by screen -ls

Try it with top: type [C]screen top[/C]. Open another terminal and run [C]screen -ls[/C], [C]screen -d xxxx[/C] and [C]screen -r xxxx.[/C]

Getting this to happen automatically when you open a terminal in say SSH is tricky. However you can write a bash script to pluck out the magic number from screen -ls and have it detach and reattach to your current terminal.

EdH 2022-08-05 18:10

I'm familiar somewhat with screen and just needed to review some things that are similar but not quite the same as with tmux, which I use much more frequently.

Anyway, no joy with any of this, but it's moved to a lower priority for the moment. I'll come back to it and play some more eventually. Thanks for reminding me of the trailing ampersand. Maybe that's part of previous failures.

Thank you to you, and all who have provided some thoughts toward an eventual resolution.


All times are UTC. The time now is 11:21.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.