LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-07-2014, 04:42 AM   #1
RamTeja
LQ Newbie
 
Registered: Feb 2014
Posts: 10

Rep: Reputation: Disabled
Unhappy Shell Scripting to automate Process of SSH Trust (Password less Login )


Please spend few min in reading my qsn.
I'm trying to automate process of giving ssh trust (password less login ).
We do have a centralized server and users will login to all other servers from that. As remembering password for 100s of servers is impossible we will provide trust to users i.e. appending id_rsa.pub of user to authorized_keys file of other Server.
I have written a small script
1. Searches the id_rsa.pub file of user.
2. scp the id_rsda.pub of user to other Server's Particular Directory.
3. ssh root@<otherserver>

Let me share my script so that you guys can debug Please Assist me with this :

Script is here and the error i'm getting is below that. I think there is something wrong with EOF block. Rest everything worked fine. Even though i have 24 lines of code I'm getting line 25 : syntax error

#! /bin/bash
read a
read b
read c
if [ -f $a ]
then
echo " $a pub key exists and checking "
if [ "$b" == "vfilvtest" ]
then
echo "can provide trust"
scp $a root@$b:/home/$c/.ssh
ssh root@$b <<EOF
cd /home/$c/.ssh
cat $a >> authorized_keys
exit
EOF
echo "trust is provided"
else
echo "u don't have access"
fi
else
echo "No user pub key"
fi



[root@vf2lvtest testprograms]# ./prog3
user3
vfilvtest
ramat1
./prog3: line 25: syntax error: unexpected end of file
 
Old 02-07-2014, 05:05 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,910

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
please use [code]here comes your script[/code] to keep formatting.
add set -vx to the beginning of the script:
Code:
#!/bin/bash
set -xv
# you may add here an echo "enter whatever" line
read a
...
and check the result
 
1 members found this post helpful.
Old 02-07-2014, 05:40 AM   #3
RamTeja
LQ Newbie
 
Registered: Feb 2014
Posts: 10

Original Poster
Rep: Reputation: Disabled
Unhappy @Pan64

Thanks for your quick response. But after adding set -xv, I just error in 26th line instead of 25. No luck at all. Once again I'm mentioning If I remove EOF Block My script is working fine but with that I'm getting an error. My intention to put EOF is it should login to other Host and execute the commands in that particular host. Please Correct me If I'm wrong.
 
Old 02-07-2014, 05:58 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,910

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
using set -xv you will see the execution of your code line by line. You need to check the last line....

unexpected end of file means an if ... then ... else ... fi or similar construct is not complete. You can try to negate those conditions:
Code:
#original code:
if (ok) then
  some code
else
  some other code
fi

#try this
if (not ok) then
  print error and exit
fi
some code
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to automatically load password in bash script using ssh login process cwh Linux - Newbie 6 05-03-2013 03:35 PM
Shell Script to automate website login vinaytp Linux - Newbie 2 09-05-2011 04:12 AM
shell script ssh: how to eliminate the login process output figo Programming 1 06-01-2009 02:05 PM
"Have to automate the SSH login procedure through shell scripting" sorav Programming 2 11-21-2007 04:53 AM
how to automate ssh login? Lotharster Linux - Networking 2 12-05-2005 12:54 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration