LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 05-27-2008, 01:16 PM   #1
mzzt1
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Rep: Reputation: 0
Linux Start up script!!


Dear Linux users,

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!!!

MzZt!!
 
Old 05-27-2008, 01:35 PM   #2
Omer Fadul
LQ Newbie
 
Registered: Feb 2005
Location: Khartoum, Sudan
Distribution: Redhat+Suse
Posts: 12

Rep: Reputation: 0
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

I hope this help a little,
 
Old 05-29-2008, 01:27 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
Please supply your distro name & version.

If you only want it restarted at boot, the usual thing is to add it to the

/etc/rc.local

file (or the equiv on your system) eg

nohup /path/to/yourprog >/path/to/yourprog.log 2>&1 &

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.
 
Old 06-02-2008, 06:47 AM   #4
mzzt1
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0
thanks a lot for your replies!!
I am using RH9.

I have a couple of file say e.g.:

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...
 
Old 06-03-2008, 01:09 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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.

Last edited by chrism01; 06-03-2008 at 08:38 PM.
 
Old 06-04-2008, 06:20 AM   #6
mzzt1
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Dear all!!

Hie!!

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!!?

MzZt...
 
Old 06-04-2008, 06:34 AM   #7
huwnet
Member
 
Registered: Jan 2006
Location: England
Distribution: Arch
Posts: 119

Rep: Reputation: Disabled
If the server has cron you could add the script to your crontab. You'd need to add a check to see if the script is already running though
 
Old 06-16-2008, 05:33 AM   #8
mzzt1
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0
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?

MzZt...
 
Old 06-16-2008, 08:51 AM   #9
huwnet
Member
 
Registered: Jan 2006
Location: England
Distribution: Arch
Posts: 119

Rep: Reputation: Disabled
You should be able to write the checks for powerfailure into the script.

"crontab -e" should work without being a superuser
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash - start remote script from local script? babag Programming 7 04-06-2008 05:46 PM
Get script to start again at a certain point in the script (bash) helptonewbie Programming 11 01-11-2008 05:49 AM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 10:15 AM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration