The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 07-17-2008
nua7 nua7 is offline
Registered User
  
 

Join Date: Mar 2008
Location: /bin/sh
Posts: 353
storing variables in array.Please help

Hi All,
I need some help with arrays. I need to take input from the user for hostname, username and password until he enters .(dot) or any other character and store the values in the variable array.

I would further connect to the hostname using username and passwd and copy files from server to these machines.

This is what I have come up with so far. Just can't figure out a way of storing values in the array variable. can someone help.

Code:
#!/usr/bin/sh
#Take input from the user
while ["host_name != "."]
do
echo "Please enter the Hostname"
read host_name 
echo "Please enter the username"
read username
echo "Please enter the password"
read password
done
 
#If you have a better way of accepting data from user , would be great!

#storing these variables in array logic here..
 
#ftp logic as below..
 
typeset SRCDIR="/root/temp1"
typeset DESTDIR="/root/"
typeset REMHOST="machB"
typeset -i STAT=0
cd "${SRCDIR}"
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "Can't cd to ${SRCDIR}" >&2
exit ${STAT}
fi
ftpput.pl -h ${REMHOST} -l ${USER} -p ${PASSWD} -d "${DESTDIR}" -B *
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
mv * "${BACKUP_DIR}/"
STAT=${?}
echo "mv failed; status ${STAT}." >&2
else
echo "FTP failed; status ${STAT}." >&2
fi
exit ${STAT}
Can someone please help me!

Thanks!
nua7