need shell or Perl script to read multiple input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting need shell or Perl script to read multiple input
# 1  
Old 08-05-2010
need shell or Perl script to read multiple input

I need shell 0r Perl script to read multiple input and do something and come out

example:

Code:
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 Smilie

Last edited by pludi; 08-05-2010 at 03:02 AM.. Reason: code tags, please...
# 2  
Old 08-05-2010
You mean like this ?

Code:
$ echo server1 server2 server3 | perl -nle 'foreach (split / /) { print }'
server1
server2
server3

# 3  
Old 08-05-2010
Code:
#!/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
}


Last edited by Franklin52; 08-05-2010 at 03:44 AM.. Reason: Please use code tags, thank you!
# 4  
Old 08-05-2010
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….

Last edited by sreedhargouda; 08-05-2010 at 03:21 AM..
# 5  
Old 08-05-2010
Within the loop, you can access array elements with $_[0], $_[1]....and so on...


-Raja
# 6  
Old 08-05-2010
Code:
#!/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

Code:
#!/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"

Last edited by Scott; 08-09-2010 at 04:19 AM.. Reason: Please use code tags
# 7  
Old 08-09-2010
how to print "sree\r" by echo command please help
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the shell script to read the .txt file as an input/data?

i have written my shell script in notepad however i am struggling to pass the data file to be read to the script the data file is of .txt format. My target is to run the shell script from the terminal and pass 3 arguments e.g. polg@DESKTOP-BVPDC5C:~/CS1420/coursework$ bash valsplit.sh input.txt... (11 Replies)
Discussion started by: Gurdza32
11 Replies

2. Shell Programming and Scripting

Read input in shell script

I want to write a script that read the input to variable. I want the input screen to have 2 lines, where the values already input will appear above the input line for example if I want to input the words below: like love live life The screen will display like this: 1. Before any input... (8 Replies)
Discussion started by: aydj
8 Replies

3. Shell Programming and Scripting

Giving automatic multiple Input to a tool from shell script

Hi, Please help me,its urgent. I have a tool that i want to run from a shell script. When we run the tool it will ask the user choice to add or delete. When user enter the choice it will then ask how many units he want to delete or add and will add or delete accordingly. Now I want to... (1 Reply)
Discussion started by: saket18@ymail.c
1 Replies

4. UNIX for Dummies Questions & Answers

Writing a loop to process multiple input files by a shell script

I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files: for i in 250.*; do || awk... (4 Replies)
Discussion started by: evelibertine
4 Replies

5. Shell Programming and Scripting

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each

The scope of the shell/perl script is to read the input text file. Validate the expiry date of each certificate and send the mail to the user. The user takes action to add the new certificate to the storage file and user owns the responsibility to update the input text file with the new certificate... (5 Replies)
Discussion started by: casmo
5 Replies

6. Shell Programming and Scripting

How to Read Multiple files in a Shell Script

Hi, Can any one tell me if i can read two files in a shell script... My actual requirement is to read the 1st text file and parse it to get the file code and use this file code to retrieve data from database and print the fetched data in the 2nd text file (I have parsed it and printed the... (2 Replies)
Discussion started by: funonnet
2 Replies

7. Shell Programming and Scripting

How can I send the input of a read line command through a shell script

Hi All, I wish to automate the unix command 'su' through a shell script. I would like to pass the content of a file as password to 'su' command. My script is as below, #! /bin/sh su userA while read line do rpm -ivh $line done < pwd.txt where pwd.txt contains the password of... (6 Replies)
Discussion started by: little_wonder
6 Replies

8. Shell Programming and Scripting

Perl script variable to read shell command

Solaris 10 Korn shell ksh, Hi there, I have figured out to get yesterday's date which is using the below command: TZ=GMT+24; date +%d-%b-%Y to get the format of 30-Sep-2008 and TZ=GMT+24; date +%Y%m%d to get the format of 20080930. I need this two format. In my perl script below I need... (4 Replies)
Discussion started by: bulkbiz
4 Replies

9. Shell Programming and Scripting

Shell script to read multiple log files

Hi all, I have to generate some report from shell script .We have stacktrace log file which generate hourly basis. So now my q is that how this shell script will read all stacktrace log file for particlular day and parse accordingly desire output. Any help or suggestion as i am newbie with... (1 Reply)
Discussion started by: esungoe
1 Replies

10. Shell Programming and Scripting

How to read email using mailx in shell script or perl

Hello, I am new to mailx and perl and I need help. I need create a shell script to read the mails on the SUN server, then parse the subject line and message body of each email to extract particular data so that I can pass these data fields in as application parameters to invoke a java... (4 Replies)
Discussion started by: jliharper
4 Replies
Login or Register to Ask a Question