I have a Linux computer that I remotely SSH into using plink on a Windows XP machine. I have a Plink program set to execute commands in a script using automated login:plink -ssh [domain name] -l [username] -pw [password] -m commands.txt >> Outputtext.txtcommands.txt only contains the followingecho Killing processps -ef | grep 'processname' | awk {print $2} | head -n 1` | xargs kill -9sleep 2echo Restarting processprocessd &echo Exiting...This script simply searches for a processname kills it then restarts it. It works everytime if the process is actually started on linux before I execute the script. However, if the process is NOT started it will actually kill the controlling terminal and exit plink.exe right on the ps -ef command.I've narrowed it down to when I'm doing the ps -ef | grep 'processname' it will return two PID's one is the process I'm searching for, and the other is the grep processname PID itselfWhen the process isn't started it will only return one PID the grep 'processname' and I think kill -9 is killing that and somehow killing plink connection or the controlling terminal? Is there any way around this?or to check if the grep 'processname' returns 2 lines meaning the process started, or if there is only 1 line then don't kill it.Not sure if I can echo #!bash a bash script out and then have the bash script execute?Or is this a weird bug in plink?
`ps | grep | kill` aborts my script prematurely
shell script;process;kill;ps