Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am into theoretical stuff and my job demands me to submit some runs on linux machine which goes on for months. In case of power failure I have to restart these runs! Now e.g. if I am running 50 loops then 49th loop is dependent on 48th and so on!! While restarting I have to use the latest file!! say 49th file using 48th as an input!! Now my problem is whenever I am away for sometime although the system is up by somebody but my jobs dont!! Is it possible in linux to use a script which runs automatically when the machine is restarted and read these loops also!!
suggest me something as this really has put me in lots of trouble!!!
suppose you name your scripts like loop1.ksh, loop2.ksh ... loop50.ksh; after a completion of each script you can add an indicator to show which script has been finished for example: on each loop file add something like echo "Script No" > Out_File then read that file on your startup script and use some for/while loops starting at the output of your Out_File till the end of your scripts, like:
#!/bin/bash
X=`cat Out_File`
for ((i="$X"; i <=50; i++)); do
bash -x loop"$i".ksh
done
Then each time your prog starts, it has to check to see what the last completed loop did, so it needs to write or update a temp file or something like that at the end of each loop.
test1.tpp
test2.tpp
test3.tpp
test.inp
test.log
test4.tpp (incomplete loop e.g. becoz of power failure)
Now my problem is whenever there is a power failure the system gets restarted! So I have to find out which is the incomplete file (test.inp has already defined the loops upto say 50) i.e. test4.tpp from above! then I have to modify test.inp manually at two places and make the latest "complete" file i.e. test3.tpp as an input and restart test.inp to write test_restart4.log, for five power failures I have to do this task five times each time locating the newest complete file and entering it as an input to test.inp and writing different restarts.log everytime. In case I am away then my jobs doesn't run! That is why I wish to write a script and also start that script at the time of boot up so that I can ask anybody to restart the machine and then my jobs wud start up automatically with the modifications listed above!
thanks again for reading my query and responding promptly :-)
MzZt...
Like i said, you need your prog to write 'loop completion' msg at the end of each loop to a completion file (see below), then, when it restarts, it can tell where it got to last time eg
test.completion
---------------
37 completed
then your prog just grabs that num and starts at 38.
Edit: Power comment:
If your system is having power failures that much you need to talk to your power supplier and/or get a UPS. Your hardware will die much faster the more often it dies/reboots.
My problem is solved and the script is indeed running even after restarting the machine taking the current loop as input!!
But I have another problem!! There are some servers where I don't have access to /etc/rc.local file since I do not have root password!! So there I cannot run my scripts!! Is there any way out of this situation!!?
But will cron solve my purpose? I need to run the script only if there is a power failure, also it appears crontab editing too require superuser password.
Any other way of running the shell script without superuser intervention?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.