1

I have a shell script which I would like to run automatically when the system starts. However, I do not have root access, and I don't have permission to run crontab. I'd like this to run when the system starts, not just when I login, so putting it in .bashrc won't work. Is there a way to do this?

Edit: The script is a data processing job which runs continuously and which I have full permissions to run. The problem is that the server is rebooted every night, so currently I have to login every morning and manually restart the script. I'm wondering if there's a way to automate this. An acceptable workaround would be setting the script to run daily at a specified time (in a way that would persist after the system is rebooted). As pointed out, I could ask the administrator to set this up as a cron job, but first I want to check if there's a (legitimate) way I can do it without requiring privilege escalation.

4
  • 1
    System-level configuration changes require root privileges. There are ways to circumvent this restriction, but that's up to you to figure out. The fact you do not have the authority to perform such changes suggest what you want to do can be considered a breach and is therefore illegal.
    – Larssend
    Commented Feb 15, 2017 at 15:39
  • Did you try @reboot in your crontab? This is accepted by Vixie cron; not sure which other implementations have it. Commented Feb 16, 2017 at 17:34
  • Cron is the way to do it, IMHO. If the server is rebooted every night, it's probably rebooted every night on a known schedule, and you can have a cron job scheduled to start some time after that. Alternatively you run a script every few minutes which checks if the job is running, and exits, unless it's not, and then it starts the job. If the job runs fine as you, then it does not need to be elevated - you simply need user-level permission to run a cron job as you - which is not elevation so much as "access to tools that exist, run at your normal privilege level."
    – Ecnerwal
    Commented Feb 18, 2017 at 18:47
  • Maybe you can make a script on your own machine that logs in and restarts the script? Commented Feb 7, 2021 at 20:58

2 Answers 2

3

If it's legitimate, above-board, and appropriate, you request that the system administrator install it, and they either agree and do so or disagree and refuse to.

Otherwise, don't. Particularly if this is at work and you enjoy paychecks, or at school and you have intentions towards graduating.

1

Ask the SysAdmins to enable cron for you, or ask them to setup a cron job to run the script.

Alternately, write a script that will ssh to the machine and launch the data processing script, and schedule the script to run on a machine you control. Use the nohup command to keep the script running the in background when the shell exits.

ssh [email protected] "data_processing_script.sh < /dev/null > std.out 2> std.err &"

Or if the system has a webserver with userdir setup, write a cgi script which will run the data processing script, and schedule a curl command on a system you control to touch the webserver.

More information about running commands in the background using ssh are here: https://unix.stackexchange.com/questions/30400/execute-remote-commands-completely-detaching-from-the-ssh-connection

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .