![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Storing commands in $variables. | Paulw0t | Shell Programming and Scripting | 7 | 08-08-2008 05:42 PM |
| Splitting the data and storing it into 2 variables | jisha | Shell Programming and Scripting | 10 | 02-17-2008 10:40 PM |
| Getting variables into a array. | vivsiv | Shell Programming and Scripting | 2 | 02-06-2008 03:45 PM |
| Storing pointer array in C | arunkumar_mca | UNIX for Dummies Questions & Answers | 1 | 08-23-2007 08:49 AM |
| awk - storing data in variables | 2nilotpal | Shell Programming and Scripting | 7 | 04-16-2004 05:32 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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}
Thanks! nua7 |
|
||||
|
This is somehow not working.Some tweaking req here
Thanks mirusnet
This somehow is not working..Some tweaking req here. Code:
#!/usr/bin/sh i=j=k=0 #Take input from the user while ["host_name != "."] do echo "Please enter the Hostname" read host_name[i] echo $hostname[i] let i=i+1 echo "Please enter the username" read username[j] echo $username[j] let j=j+1 echo "Please enter the password" read password[k] echo $password[k] let k=k+1 done |
| Sponsored Links | ||
|
|