The correct way to do this is using Crontab - if you don't have access to your crontab you really should speak to your administrator - they probably don't want you to be running scheduled jobs. That said, before you say to don't have permissions for the crontab command, try run "crontab -e" - each user has their own cron file, and crontab - will attempt to edit yours. (I note when I run crontab by itself as a user it just freezes)
You can make pretty much any job run in the background by appending an "&" character to the job. I would urge against this, but you could write a script in a while loop which checks the time, then waits a minute, checks again etc, and if it matches executes the command. You could run this script with & to run it in the background. You could also get into trouble for subverting the system....
Another command to look up is "screen". This allows you to attach and detach your terminal from the console - it can be a useful way of running something in the background, but being able to see and interact with it (You can screen, then execute the program in the foreground, then detach from screen, and reattach later on)
EDIT
A script to check the time once a minute and run the command at the appropriate time:
#! /bin/bash
RUNAT="07:54"
while [ 1 ]
do
DATE=`/bin/date +%H:%M`
if [ $DATE. = $RUNAT. ]
then
/path/to/script.sh
fi
sleep 60
done
Save this as (for example) mycron.sh, chmod 755 mycron.sh so it executes,
Modify the RUNAT line to trigger when you want your script to run, then execute this script as mycron.sh & so it runs in the background.
This script will not cause any stacks to overflow because it only executes the command once per day, it does not "chain itself"
crontab -e
is also not permitted. As you suggested to write a script using while loop, will that not cause stack to overflow ? and you mentioned "waits a minute", it means to usesleep
? – learner1 – 2016-02-15T09:48:39.693I've modified my answer with an appropriate script and usage instructions - yes, it uses sleep, no it won't cause the stack to overflow. – davidgo – 2016-02-15T18:59:17.490
Thanks a lot @davidgo . Script is working damn fine. But I'm worried about resources (memory, CPU) utilization. If I never gonna kill the job, will there be any adverse effect on resources ? – learner1 – 2016-02-16T03:06:23.320
Excluding the script you run - which I can't comment on - the resources utilised by the script are negligible on any modern PC or server, and would probably not be discernible (save for its appearance in process lists etc - its not stealthy), let alone of any consequence. – davidgo – 2016-02-16T03:37:23.803