connecting servers using SSH - help needed

Hi all,

I have a script written successfully and tuned by our members, now I am trying to execute this script from a taxi server.

My aim is I want to connect to four servers via ssh where I want to ran a script or run some commands and write the output to a file in the Taxi server.

I tried to write some script using some sample script but failed to succeed. Please help me.

Regards,
Senthil kumar AK

What failed, the ssh authentication? Need more input - write or describe your errors please.

Hi all,

I tired this with a script available in the froum and its work fine for me now. I have created a public key so that the server ssh without any password prompt.

But now there is only one issue which I think I need some help.

This is the script which I have written in the taxi server where form I am connecting

bash-2.05$ cat connect.sh
#!/usr/bin/sh

while read box
do
ssh -n $box -l mvelmu 'hostname ; ksh /axphome/mvelmu/count.ksh' >> machineaddress.txt
done < "output.txt"

but when I ran this above script its returning with the results in the output.txt, but in the console I am able to see some system generated messages, how to suppress that messages.

THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS AND BUSINESS PURPOSES
ONLY. INDIVIDUALS ATTEMPTING UNAUTHORIZED ACCESS AND NON-BUSINESS
UTILIZATION ARE LIABLE FOR DAMAGES INCLUDING THE VALUE OF DIVERTED
RESOURCES AND CRIMINAL PROSECUTION.

By continuing to login you agree to the above and accept responsibility
for all of your actions.

Repeating four times as I am connecting to four servers.

regards,
senthilkumar AK

Hi Senthil,

You can comment those Messages in the ssh file by using

*****************
THIS SYSTEM IS ......

*****************

and use in you file as

ssh -n $box -l mvelmu 'hostname 2>&1 | grep -v '^*' ; ksh /axphome/mvelmu/count.ksh' >> machineaddress.txt

Thanks,
JeganR

Hi Jegaraman,

I have tried this but i am getting following error.

for all of your actions.
THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS AND BUSINESS PURPOSES
ONLY. INDIVIDUALS ATTEMPTING UNAUTHORIZED ACCESS AND NON-BUSINESS
UTILIZATION ARE LIABLE FOR DAMAGES INCLUDING THE VALUE OF DIVERTED
RESOURCES AND CRIMINAL PROSECUTION.

By continuing to login you agree to the above and accept responsibility
for all of your actions.
Usage: grep [OPTION]... PATTERN [FILE]...
Usage: grep [OPTION]... PATTERN [FILE]...
Usage: grep [OPTION]... PATTERN [FILE]...
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

Hi Senthil,

Can u just comment out each of the message using * and grep -v '^*'

Just print ur script on the post and we shall see to it..

Rgds
JeganR

this is the earlier script

bash-2.05$ cat connect.sh
#!/usr/bin/sh
while read box
do
ssh -n $box -l mvelmu 'hostname; ksh /axphome/mvelmu/count.ksh' >> output.txt
done < "machineaddress.txt"

after changing with grep -v option

bash-2.05$ cat connect_new.sh

#!/usr/bin/sh
while read box
do
ssh -n $box -l mvelmu 'hostname 2>&1 | grep -v '^*' ; ksh /axphome/mvelmu/count.ksh' >> output.txt
done < "machineaddress.txt"

Jegaraman i am waiting for your reply.

Hi Senthil,

Can u pl send the output of the shell script execution.

Hi Jegaraman,

here are the output.

bash-2.05$ cat connect.sh
#!/usr/bin/sh
while read box
do
ssh -n $box -l mvelmu 'hostname; ksh /axphome/mvelmu/count.ksh' > /home/mvelmu/$box.txt
done < "/home/mvelmu/machineaddress.txt"
bash-2.05$ cat connect_new.sh
#!/usr/bin/sh
while read box
do
# ssh -n $box -l mvelmu 'hostname; ksh /axphome/mvelmu/count.ksh' > /home/mvelmu/$box.txt
ssh -n $box -l mvelmu 'hostname 2>&1 | grep -v '^*' ; ksh /axphome/mvelmu/count.ksh' >> /home/mvelmu/$boxoutput.txt
done < "/home/mvelmu/machineaddress.txt"

Output for the script.

bash-2.05$ ./connect_new.sh
./connect_new.sh: * ; ksh /axphome/mvelmu/count.ksh: not found
./connect_new.sh: * ; ksh /axphome/mvelmu/count.ksh: not found
./connect_new.sh: * ; ksh /axphome/mvelmu/count.ksh: not found
./connect_new.sh: * ; ksh /axphome/mvelmu/count.ksh: not found
bash-2.05$ THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS AND BUSINESS PURPOSES
ONLY. INDIVIDUALS ATTEMPTING UNAUTHORIZED ACCESS AND NON-BUSINESS
UTILIZATION ARE LIABLE FOR DAMAGES INCLUDING THE VALUE OF DIVERTED
RESOURCES AND CRIMINAL PROSECUTION.

By continuing to login you agree to the above and accept responsibility
for all of your actions.
THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS AND BUSINESS PURPOSES
ONLY. INDIVIDUALS ATTEMPTING UNAUTHORIZED ACCESS AND NON-BUSINESS
UTILIZATION ARE LIABLE FOR DAMAGES INCLUDING THE VALUE OF DIVERTED
RESOURCES AND CRIMINAL PROSECUTION.

By continuing to login you agree to the above and accept responsibility
for all of your actions.
THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS AND BUSINESS PURPOSES
ONLY. INDIVIDUALS ATTEMPTING UNAUTHORIZED ACCESS AND NON-BUSINESS
UTILIZATION ARE LIABLE FOR DAMAGES INCLUDING THE VALUE OF DIVERTED
RESOURCES AND CRIMINAL PROSECUTION.

By continuing to login you agree to the above and accept responsibility
for all of your actions.
THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS AND BUSINESS PURPOSES
ONLY. INDIVIDUALS ATTEMPTING UNAUTHORIZED ACCESS AND NON-BUSINESS
UTILIZATION ARE LIABLE FOR DAMAGES INCLUDING THE VALUE OF DIVERTED
RESOURCES AND CRIMINAL PROSECUTION.

By continuing to login you agree to the above and accept responsibility
for all of your actions.
Usage: grep [OPTION]... PATTERN [FILE]...
Usage: grep [OPTION]... PATTERN [FILE]...
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.
Try `grep --help' for more information.
Try `grep --help' for more information.

Please let me know if done some thing wrong on it

Hi Senthil,

I think 2>&1 will alone do it. I think u can remove grep command and all other alterations.....

Tried but still i am getting this output

bash-2.05$ cat connect_new.sh
#!/usr/bin/sh
while read box
do
ssh -n $box -l mvelmu 'hostname 2>&1 ; ksh /axphome/mvelmu/count.ksh' >> /home/mvelmu/$boxoutput.txt
done < "/home/mvelmu/machineaddress.txt"
bash-2.05$ ./connect_new.sh
THIS SYSTEM IS RESTRICTED TO AUTHORIZED USERS AND BUSINESS PURPOSES
ONLY. INDIVIDUALS ATTEMPTING UNAUTHORIZED ACCESS AND NON-BUSINESS
UTILIZATION ARE LIABLE FOR DAMAGES INCLUDING THE VALUE OF DIVERTED
RESOURCES AND CRIMINAL PROSECUTION.
By continuing to login you agree to the above and accept responsibility
for all of your actions.

Hi Jegaraman,

Is it we need to add dev/null there ..?

Senthil.