Can someone please help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Can someone please help!
# 8  
Old 07-18-2008
Code:
  ...
  read host_name
  if [ "$host_name" = done ] ; then break; fi
  ...

Also for i in c is not valid syntax. Also, why use three indices (c, d and e) when just one will do?
# 9  
Old 07-18-2008
I have to take user input till user enters "done" , so I used the while loop.I have added the if line code after the read statement.


Also , I need to have a different count of all three arrays , so kept different variables.

I know I kept on bugging you for small queries , but this script simply won;t work!

I just need to pick up hostnames, usernames and passwords from the user and put some files/folder onto the hosts.

Can anyone give me a script that would work. (I know this is too much of asking...)

Here's the modofied version:

Code:
#!/usr/bin/sh
##Take input from the user
c=d=e=0
while [ "$host_name" != done ] 
do
  echo "Please enter the host_name"
  read host_name
  if [ "$host_name" = done ] ; then break; fi
  store_hostname[$c]=$host_name
  c=$(( c + 1 ))
  echo "Please enter the username"
  read username
  echo $username
  store_username[$d]=$username
  d=$(( d + 1 ))
  echo "Please enter the password"
  read password
  echo $password
  store_password[$e]=$password
  e=$(( e + 1 ))
done

len= size of array
for i in $len
do
#Create a destination directory
ssh -q ${store_username[$d]}@${store_host_name[$c]} mkdir temp
#scp files to host
scp -r /root/temp ${store_username[$c]}@${store_host_name[$c]}:/root/
done

# 10  
Old 07-18-2008
Code:
len= size of array
for i in $len
do
#Create a destination directory
ssh -q ${store_username[$d]}@${store_host_name[$c]} mkdir temp
#scp files to host
scp -r /root/temp ${store_username[$c]}@${store_host_name[$c]}:/root/
done

--change to ->

Code:
len= ${#store_username[@]}
for(( i =0; i<$len; i++))
do

#Create a destination directory
ssh -q ${store_username[$i]}@${store_host_name[$i]} mkdir temp
#scp files to host
scp -r /root/temp ${store_username[$i]}@${store_host_name[$i]}:/root/

done

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question