I need shell 0r Perl script to read multiple input and do something and come out
example:
echo � enter the host names separated by space �
read servers
foreach @servers
{ do
do something
done}
Here host names like host1 host2 host3 . . . . . . . so on
Please help me
agn
August 5, 2010, 1:51am
2
You mean like this ?
$ echo server1 server2 server3 | perl -nle 'foreach (split / /) { print }'
server1
server2
server3
#!/usr/bin/perl
print "Enter inputs separated by comma\n";
# I am not doing error checking here....
my $input = <STDIN>;
chomp $input;
my @hosts = split(/\,/, $input);
foreach(@hosts) {
print "$_.....\n";
# do whatever you want
}
thanks for your quick reply
as u above mentioned
how print each array input
means
if I have entered serve1 srver2 server 3
foreach(@hosts ) {
print �$1� ---> output will server1? if not how to print
Print �$2� ---> output will server2? if not how to print
So on..
I am new to Perl please don't feel bad�.
Within the loop, you can access array elements with $[0], $ [1]....and so on...
-Raja
#!/usr/bin/sh
# sreedhar
echo " welcome Please wait all hosts are listing\n"
echo "-----------------------------------------\n"
echo "`/alcatel/Kernel/etc/HostDeclarer.pl -list`"
echo " ----------------------------------------\n"
echo " please enter the User Name to be changed:"
read User
echo " please enter the Password:"
read Password
echo " please Enter the Host Names sapareted by space ex:host1 host2 host3\n"
read servers
echo $servers | perl -nle 'foreach (split / /) { print }' > server_list
echo '#!/usr/local/bin/expect' > sree_expt
echo "spawn passwd $User" >> sree_expt
echo 'expect "New password:"' >> sree_expt
echo send "$Password\r" >> sree_expt
echo 'expect "Re-enter new password:"' >> sree_expt
echo send "$Password\r" >> sree_expt
echo "expect eof" >> sree_expt
-------------------------------
out put of sree_expt is like below
#!/usr/local/bin/expect
spawn passwd sree
expect "New password:"
send sree1^M
expect "Re-enter new password:"
send sree1^M
expect eof
but i need ouput like
send "sree1\r"
how to do echo to get like send "sree1\r"
how to print "sree\r" by echo command please help
Scott
August 9, 2010, 3:21am
8
Hello sreedhargouda
Try escaping the \r:
echo '#!/usr/local/bin/expect' > sree_expt
echo "spawn passwd $User" >> sree_expt
echo 'expect "New password:"' >> sree_expt
echo send "$Password\\\r" >> sree_expt
echo 'expect "Re-enter new password:"' >> sree_expt
echo send "$Password\\\r" >> sree_expt
echo "expect eof" >> sree_expt
how to put \r end of the line by using sed
eaxample is output is like password i need to put \r end of the line means password\r
how to dothis please help me