If you do not have a strict format requirement for storing the user for ip mapping, the following example script will be used:
user_210="radek"
user_209="mike"
function define_alias
{
local ip_last_part=`echo $1 | cut -d ' ' -f1 | cut -d '.' -f4`
eval user=$`echo "user_$ip_last_part"`
echo "User '$user' identified for ip ending in '$ip_last_part'"
alias sites="cd /var/lib/code/$user"
echo "Alias defined : `alias sites`"
}
export SSH_CLIENT='10.0.0.210 53039 22'
define_alias $SSH_CLIENT
export SSH_CLIENT='10.0.0.209 53039 22'
define_alias $SSH_CLIENT
If you do not want to use this function, you copy the code in the function outside and use the domino clause to get the last part of the IP address. Like this:
user_210="radek"
user_209="mike"
ip_last_part=`env | grep -i SSH_CLIENT | cut -d ' ' -f1 | cut -d '.' -f4`
eval user=$`echo "user_$ip_last_part"`
echo "User '$user' identified for ip ending in '$ip_last_part'"
alias sites="cd /var/lib/code/$user"
echo "Alias defined : `alias sites`"
NTN,
Madhur Tanwani
source
share