I connect to my school's Linux Lab frequently to work on my programming assignments remotely. Sometimes, when there are lots of other students logged in to the server, the connection is slow, and I lose work during connection timeouts. There are several servers to choose from in the lab, and I want to be able to automatically run who as soon as the connection is made, so I can see how crowded the server is, and use another one if it's pretty full. Right now, I use a function in my .bash_aliases file to streamline the connection and password entry:
In file ~/.bash_aliases:
#!/bin/bash
# ssh to the Linux lab. Takes hostnames defined in ~/.ssh/config as
# parameters
function sshll()
{
if [ "$@" ]
echo "Connecting to hostname $@";
sshpass -f <password_file> ssh $@;
else
echo "Connecting to default host";
sshpass -f <password_file> ssh <user@ipaddress>;
fi
}
This works, so I added who to the end of the ssh commands:
In file ~/.bash_aliases:
#!/bin/bash
# ssh to the linux lab. Takes hostnames defined in ~/.ssh/config as
# parameters
function sshll()
{
if [ "$@" ]
echo "Connecting to hostname $@";
sshpass -f <password_file> ssh $@ 'who';
else
echo "Connecting to default host";
sshpass -f <password_file> ssh <user@ipaddress> 'who';
fi
}
This connects, enters my password automatically, and runs who, but then closes the connection. Is there a way I can run who automatically, without closing the connection afterward?