1753521 Members
4890 Online
108795 Solutions
New Discussion юеВ

rc file for ssh

 

rc file for ssh

I have a script that works fine for ssh but not scp, the who command does not work without a tty.
I would like a sollution that works for both ssh and scp?

file /.ssh/rc

#!/usr/bin/ksh

LOGIN_HOST=$(who -um | awk '{print $NF}')

case $LOGIN_HOST in
'system hostname')
echo "OK"
;;
'system ip')
echo "OK"
;;
*)
KILL_PTS=$(who -um | awk '{print $2}')
LOGOUT=$(ps -ef | grep $KILL_PTS | grep -v grep | grep sshd | awk '{print $2}')
kill -9 $LOGOUT
;;
esac
2 REPLIES 2
Nicolas Dumeige
Esteemed Contributor

Re: rc file for ssh

Hello,

If you want to know if ksh is executed in interactive mode use this test :

if [[ -o interactive ]] ; then
...
else
...
fi

Cheers

Nicolas
All different, all Unix

Re: rc file for ssh

for the information:
This is a script that will let root in for a sincle server. This script will not affect other protocols as telnet :-).

With the script:
#!/usr/bin/ksh

if [[ -o interactive ]]
then
echo "STATEMENT 1"
else
echo "STATEMENT 2"
LOGIN_HOST=$(who -um | awk '{print $NF}')

case $LOGIN_HOST in
'')
echo "OK"
;;
'')
echo "OK"
;;
*)
KILL_PTS=$(who -um | awk '{print $2}')
LOGOUT=$(ps -ef | grep $KILL_PTS | grep -v grep | grep sshd | awk '{print $2}')
kill -9 $LOGOUT
;;
esac
fi

I get the following output on scp:
root@'s password:
STATEMENT 2
$ process not attached to terminal

for ssh i get the following output:
$ ssh -l root
root@'s password:
STATEMENT 2
OK


so the:
if [[ -o interactiv ]]
doesn't work