How to get rid of extra characters in linux process ID using shell script -


i m trying kill process pid, , script found web.

pid=`ps -ef | grep myprocess | grep -v grep | awk '{print $2}'`   echo -e killing myprocess pid: $pid..   

output: killing myprocesswith pid: 13275^m..

does know why there ^m , how rid of because kill command failed run :

**arguments must process or job ids** 

i searched online still got no idea how overcome this.. appreciated!! thanks!

first, syntax wrong. use $() call command , store output variable

pid=$(ps -ef | grep myprocess | grep -v grep | awk '{print $2}') 

second, can in 1 awk statement without need grep processes.

ps -eo pid,args | awk '/myproces[s]/{cmd="kill  "$1;print cmd; }' 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -