1833827 Members
2369 Online
110063 Solutions
New Discussion

script

 
Indrajit_1
Valued Contributor

script

Hi All;

Do u have any script for killing old ssh process?

Cheers
Indrajit
Never Ever Give Up
6 REPLIES 6
RAC_1
Honored Contributor

Re: script

Many things to check.

1. How do you decide "old session"
2. Old logins/sessions do not terminate on it's own, it could be on account ssh also. Check your ssh version and update to latest.
3. Check ssh config files to see if you have any option there.
There is no substitute to HARDWORK
Muthukumar_5
Honored Contributor

Re: script

Get ssh process as,

# ps -ef | grep ssh

kill them with kill command.

Or simply as,

# kill -9 `ps -ef | grep ssh | awk '{ print $2 }'`

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: script

Hello,

You can stop all SSH process by,

#/sbin/init.d/secsh stop

or simply by,

# kill -9 `ps -ae |grep -i ssh |awk '{print $1}'`

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Indrajit_1
Valued Contributor

Re: script

Hi;

i am trying to find some script which i can execute automatically through crontab or controlm.
The script should able to kill 15 days old ssh process.



Cheers
Indrajit
Never Ever Give Up
James R. Ferguson
Acclaimed Contributor

Re: script

Hi Indrajit:

This gets greatly simplified if you leverage the UNIX95 (XPG4) mode of 'ps'.

For instance, if you wanted to discriminate "too long" on the elapsed time of a process, use 'etime':

# UNIX95= ps -C init -o pid= -o comm= -o etime=

This would return the 'pid', the 'comm'and name (basename) and the elapsed time of a process named by '-C' in this example, 'init'.

The value here is several fold. Using the '-C name' selects *only* processes matching 'name'. A grep for a name "tar" would also find processes named "start" -- probably not what you want!

The next value of the UNIX95 mode is that times, like the 'etime' are formatted in days, hours, minutes and seconds, like:

79-09:35:22

...for 79-days, 9-hours, 35-minutes and 22-seconds. This makes comparisons like greater than 15-days simple.

This should get you on the right path.

Regards!

...JRF...
Indrajit_1
Valued Contributor

Re: script

Hi All;

Thanks a lot for ur kind support. i will try to write a script which may help me to kill old ssh process in an specific interval of time.

Thanks to James. i think ur input would help me to resolve my issue.

Cheers
Indrajit
Never Ever Give Up