How to restart a script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to restart a script?
# 1  
Old 04-21-2010
How to restart a script?

Hello, I created a shell script in /etc/init.d and it already runs at boot. However I cannot figure out how to make it run just like typing "scrip_name start"

I can run it like this ./script_name but since I am doing remote log in whenever I log off the script stops and I also don't want to run nohup

How can I create the option or just start? I need to send the command from a windows machine using plink

Thanks
# 2  
Old 04-21-2010
MySQL

Maybe you can write yourself it

For simple example in yourscript

Code:
case "$1" in
        start)
                /etc/init.d/yourscript
                ;;
        stop)
                pkill -9 yourscript
                ;;
        restart)
                pkill -9 yourscript
                /etc/init.d/yourscript start
                ;;
 status)
  if [ `ps aux | grep yourscript | grep -v grep` -eq 0 ] ; then
        pid=`ps aux | grep sshd | grep -v grep | awk {'print $2'}`
        echo "$0 is (pid $pid) running"
                else
                echo "$0 is dead"
  fi  
  
        *)
                echo "Usage: $0 {start|stop|restart|status}"

Code:
/etc/init.d/yourscript status

/etc/init.d/yourscript start


Last edited by ygemici; 04-21-2010 at 03:55 PM..
# 3  
Old 04-21-2010
Thanks for your reply. I just tried that and I could actually run name_of_script start and it would start but the problem is since I am login in remotely as soon as I close the terminal the script stops =/
# 4  
Old 04-21-2010
If you don't want to use nohup, you'll have to redirect it's stdin, stdout, and stderr to files or /dev/null yourself. Otherwise these resources will cease to exist when you close your terminal.
# 5  
Old 04-21-2010
Quote:
Originally Posted by Corona688
If you don't want to use nohup, you'll have to redirect it's stdin, stdout, and stderr to files or /dev/null yourself. Otherwise these resources will cease to exist when you close your terminal.
How do I redirect the output?

Thanks
# 6  
Old 04-21-2010
If you're using zsh or bash try:

Code:
disown -h

# 7  
Old 04-21-2010
Ok I did
Code:
 plink -pw password name@ip nohup /etc/init.d/script.ssh &; disown -h

But it still gets killed =/ Any more ideas? Thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Restart logic in script

I have a question regarding the restart logic in scripts. I have a script named "JOB1" which has 5 steps and every step has a program. Suppose my script fails at 4th step and the first 3 steps have completed successfully. I want to start my script from 4th step directly without doing any change... (1 Reply)
Discussion started by: champ2108
1 Replies

2. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

3. Shell Programming and Scripting

Need script to restart the services

Hi Guys, I need bash script to restart the service. 1. Disable the service called SASM svcadm disable sasm 2. if service went to maintenance mode then it shuld clear it with below command svcadm clear sasm 3.or else it should restart the mysql service /etc/init.d/mysql stop... (1 Reply)
Discussion started by: bapu1981
1 Replies

4. Shell Programming and Scripting

Script to restart a process

I have written a script which checks for a file if that is being updated or not. If the files is not being updated then it will restart the process. #!/bin/sh DATE=`date +%Y%m%d%H%M%S` LOG_FILE=/var/xmp/log/XMP_* INCEPT=`ls -l $LOG_FILE |awk '{print $5}'` PROC=`xms show pr |grep -i... (3 Replies)
Discussion started by: Siddheshk
3 Replies

5. Shell Programming and Scripting

Modifying the Restart Script

Hello, I have a shell script which calls for an existing script with appropriate parameters. It looks something like this. -------------------------------------------------------------------------- #!/bin/bash sh /root/ams_rc stop_shepherd > /dev/null sleep 30 sh /root/ams_rc... (9 Replies)
Discussion started by: Siddheshk
9 Replies

6. Shell Programming and Scripting

Restart and then continue script

How can I get a script to complete a update, varifiy completion, resboot, and continue with script? Is it possbile to get script to add itself to the "startup application" list #!/bin/bash clear sudo apt-get update #Verify/test the update completed #Reboot #Start/comtinue... (9 Replies)
Discussion started by: wolfgangcs
9 Replies

7. Shell Programming and Scripting

restart logic in a script

Hi I have a script as follows Function func0 <Set of validations done> Function Func1 <Set of commands and some of the variables set> Function Func2 <Set of commands and some of the varibales set> Function Func3 <Call a job(It is a datastage job which is called> Main job Call func0... (2 Replies)
Discussion started by: dnat
2 Replies

8. Shell Programming and Scripting

Any Restart Script?

Hi, I would like to check if there's any sample of restart script for my AIX server. I'm planning to restart it every month. Thanks. (5 Replies)
Discussion started by: ademah
5 Replies

9. UNIX for Dummies Questions & Answers

Restart Script

Hi, I am writing a script and need to goto the start of the script if an incorrect command is wrongly entered what can i do. Andy (1 Reply)
Discussion started by: chapmana
1 Replies

10. Shell Programming and Scripting

How to restart a script from the top

Hi folks! I'm starting to get pretty good at this, I still have a question left. I can't seem to figure out how to start a script from the top once it completes... SunOS 5.7 with Bash 2.01. Here's a "schedule" of my script: 1. First I have some functions declared 2. The functions are... (2 Replies)
Discussion started by: indo1144
2 Replies
Login or Register to Ask a Question