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

Maybe you can write yourself it

For simple example in yourscript

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}"
    
/etc/init.d/yourscript status

/etc/init.d/yourscript start

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 =/

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

If you're using zsh or bash try:

disown -h

Ok I did

 plink -pw password name@ip nohup /etc/init.d/script.ssh &; disown -h

But it still gets killed =/ Any more ideas? Thanks

You need to run disown on the remote server, not locally.

Lets try this

 plink -pw password name@ip nohup /etc/init.d/script.ssh &\; disown -h