I have written this small script to add an entry to a remote /etc/hosts file which needs to be run from our central admin box and is passed one parameter $1 <hostname>
#!/bin/ksh
echo "Which host entry would you like to add to $1"
read host_to_add
echo "what is the IP address?"
read ip
echo "Adding $host_to_add $ip to $1"
ssh $1 'echo $host_to_add $ip >> /etc/hosts'
but obviously this doesnt work because the variables arent passed over when issuing the ssh statement at the end there, so what i actually get in the target machines host file is a blank line at the end
Does anybody have an idea on how I can get around this???
#!/bin/ksh
if [ $# -ne 1 ]; then
echo usage: "./add_a_host <hostname>"
exit
fi
ping $1 2 > /dev/null
if [ $? != 0 ] ; then
echo " "
echo "Couldn't ping $1, cannot proceed with script"
exit
else
echo "Which host entry would you like to add to $1"
read host_to_add
echo "what is the IP address?"
read ip
echo "Adding $host_to_add $ip to $1"
ssh $1 "echo $ip $host_to_add >> /etc/hosts"
fi
Does anybody know any ways I can pretty it up a little ?