Script to run non-stop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to run non-stop
# 1  
Old 11-06-2007
Script to run non-stop

Hi All,

I am on a Solaris OS and i have come up with a csh script named " mycshscript " which will grab data from a datalog file & format the grabbed data & upload formated version to web server. I would want to have this script to run non-stop so that the latest can be captured since data is always appending to the datalog file. Below is a skeleton of my script using a while loop to loop non-stop.

My question is that
1) Does closing my command console stop the running of my script?
2) If i want to stop my script from running, how am i able to do it in a clean manner?


Code:
#!/bin/csh

set num = 1

while ($num == 1)

......
.......

end

# 2  
Old 11-06-2007
Quote:
Originally Posted by Raynon
Does closing my command console stop the running of my script?
Normally.

The traditional solution is

Code:
nohup myprogram &

and run it from a shell without job control.

This will

(a) run the program in the background
(b) ignore any SIGHUP generated by the terminal "hanging up".
# 3  
Old 11-06-2007
Hi Porter,

1) How do i stop the process if i need to?
2) how do i need to create a while loop for this ?
3) If there's an echo command, will it be printed out ?
4) Do i need to add in the " nohup myprogram & >/dev/null 2>&1 " just like cronjob to remove all the echoing and printing command ?
# 4  
Old 11-06-2007
Quote:
and run it from a shell without job control.
Not necessarily.

I could do the same with ' ksh / zsh ' - which has a good job control.

Would that create any difference ?
# 5  
Old 11-06-2007
Quote:
Originally Posted by Raynon
Hi Porter,

1) How do i stop the process if i need to?
get the process id and use kill
Quote:
2) how do i need to create a while loop for this ?
already there is a while in your script
Quote:
3) If there's an echo command, will it be printed out ?
use re-direction operators to redirect both stderr and stdout to log-file
Quote:
4) Do i need to add in the " nohup myprogram & >/dev/null 2>&1 " just like cronjob to remove all the echoing and printing command ?
thats a better way of doing it.
# 6  
Old 11-06-2007
[QUOTE=matrixmadhan;302144018]get the process id and use kill

already there is a while in your script

use re-direction operators to redirect both stderr and stdout to log-file


1) How do i get the process id and kill it ? What's the command?

2) I see. Thanks

3) What if there's no redirection operators ? What will happen ?

4) Can i use this ?
nohup myprogram & >/dev/null 2>&1
# 7  
Old 11-06-2007
Quote:
Originally Posted by matrixmadhan
Would that create any difference ?
Run it from a shell that when you try to exit the shell doesn't refuse because it complains you still have jobs running.

Quote:
Originally Posted by Raynon
3) What if there's no redirection operators ? What will happen ?
man nohup, typically end up with a file called "nohup.out".

Quote:
Originally Posted by Raynon
4) Can i use this ?
nohup myprogram & >/dev/null 2>&1
Sure, as always, give it a go, see what it does, try and break it.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Shell Programming and Scripting

How to run a process continuously for an hour then stop?

Hi I have a shell script I would like to run it has to run twice a day every 5 seconds for an hour I can do this with cron but I was hoping there was an easier way. Is there a way to make a process sleep only at a certain time of day say between 1 and 2 pm? Or under certain conditions? Any help... (8 Replies)
Discussion started by: Paul Walker
8 Replies

3. Shell Programming and Scripting

Script fails to run properly when run from CRONTAB

Hello all, I'm trying to write a script to gather and send data and it works just fine at the bash command line, but when executing from CRON, it does not run properly. My scripting skills are pretty limited and there's probably a better way, but as I said it works at the command line, but... (12 Replies)
Discussion started by: rusman
12 Replies

4. Shell Programming and Scripting

how to run an already made script run against a list of ip addresses solaris 8 question

how to run an already developed script run against a list of ip addresses solaris 8 question. the script goes away and check traffic information, for example check_GE-VLANStats-P3 1.1.1.1 and returns the results ok. how do I run this against an ip list? i.e a list of 30 ip addresses (26 Replies)
Discussion started by: llcooljatt
26 Replies

5. Shell Programming and Scripting

Stop child script by stoping parent script

Hi everyone, I have this problem with a script I'm writting. I want to execute a code running in the background several times through a script. I am writting it like that parent_script for a in 1 2 3 4 5 do exec test -n $a done What I want to do is when parent_script is killed,... (0 Replies)
Discussion started by: geovas
0 Replies

6. UNIX for Advanced & Expert Users

rc.d script to stop not workign

I have a simple script that I have put in all the rc.d directories from 1-6 and have named it K20blah and S20blah .I am on red hat linux and I see that when i do reboot the S20blah is ignored but the K20blah is executed during startup . Any suggestions? #! /bin/sh # /etc/init.d/blah # #... (3 Replies)
Discussion started by: gubbu
3 Replies

7. AIX

My script didn't run every run every minute at cronjob

In my cronjob, I would like to schedule my script.sh to run every minutes. I crontab -e and have in line below but it didn't seems to run at all. * * * * * script.sh When I run it manually, I can run it. Is that anything wrong with the above line? If I change it to something like below,... (4 Replies)
Discussion started by: ngaisteve1
4 Replies

8. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

9. UNIX for Advanced & Expert Users

script to run different shells which run different processes

Hi, Would like to ask the experts if anyone knows how to run a script like this: dtterm -title shell1 run process1 on shell1 dtterm -title shell2 run process2 on shell2 cheers! p/s: sorry if i used the wrong forum, quite concussed after watching world cup for several nights; but I... (2 Replies)
Discussion started by: mochi
2 Replies
Login or Register to Ask a Question