LinuxQuestions.org
Review your favorite Linux distribution.
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 01-31-2011, 04:42 AM   #1
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Rep: Reputation: 0
Question Script question: Shell script in kde to log in on a server with ssh


Hi everyone,

I created a script that a should run, and that automaticly logs them in on a server via following command: ssh -i password -XC username@server

The script asks for the password of the user and then it should log in to the server.

Here is the code I wrote:
Code:
username=`eval whoami`
password=`kdialog --title "Log in " --password "Enter password:"`
server="servername_or_ip"
ssh -i $password -XC $username@$server
Does anybody have an idea how I can pull this off?

I get following error when I execute the script:
Quote:
not accessible: No such file or directory.
: Name or service not known
I suppose the problem is the way I execute the ssh, but I don't know how to execute it in another way.

Thx in advance!
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 01-31-2011, 05:04 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

First and probably biggest problem I see: You cannot give the ssh command a password with an option (-i is used for something else, there is no option to supply the password). You need to give it by hand or set up ssh to use password-less log in.

Hope this helps.
 
Old 01-31-2011, 06:11 AM   #3
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Original Poster
Rep: Reputation: 0
Ok I tried it before and it worked, but now it doesn't work anymore, so I guess you are right
So then my code would be:
Code:
username=`eval whoami`
password=`kdialog --title "Log in " --password "Enter password:"`
server="servername_or_ip"
ssh -XC $username@$server
Something to give enter the password
Ssh to use password-less log in is impossible. I do not have root access.

My script still gives the error
Quote:
: Name or service not known

Last edited by c4719929; 01-31-2011 at 06:14 AM.
 
Old 01-31-2011, 06:20 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,
Quote:
Originally Posted by c4719929 View Post
Code:
username=`eval whoami`
password=`kdialog --title "Log in " --password "Enter password:"`
server="servername_or_ip"
ssh -XC $username@$server
Something to give enter the password
The bold parts are not needed:
- the whoami command doesn't need to be evaluated,
- the password dialogue has no use,
- ssh will ask for the password, no need to do anything extra.

Code:
username=`whoami`
server="servername_or_ip"
ssh -XC $username@$server
Quote:
Ssh to use password-less log in is impossible. I do not have root access.
You do not need root access to set up password-less ssh (assuming that you don't use root to ssh [you shouldn't....]).

Hope this helps.
 
Old 01-31-2011, 07:03 AM   #5
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Original Poster
Rep: Reputation: 0
Still having the problem with the
Quote:
: Name or service not known
errorcode.
It's like the script doesn't detect ssh -XC $username@$server as a command.
Do I need to add something to the script like "#! /bin/csh -f" or something else?

The problem is I may not set up the server for password-less login. Its at my work. I can't change anything to the configuration. So we'll have to do it by entering the password in the console.

Thx for your help so far :-)

Last edited by c4719929; 01-31-2011 at 07:11 AM.
 
Old 01-31-2011, 07:18 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

It would be helpful if you posted the code you are using at the moment.....

Anyway: The below code works on my side:
Code:
#!/bin/bash

username=`whoami`
server="exile"
ssh -XC $username@$server
- exile is the name of one of my servers, substitute it with the valid hostname (or IP) of the machine you want to connect to,
- I do get a message about the -X option, but is is not a show-stopper. You might or might not need the -XC flags.

Hope this helps.
 
Old 01-31-2011, 07:21 AM   #7
Ashkan_s
Member
 
Registered: Jul 2008
Distribution: Fedora
Posts: 77

Rep: Reputation: 22
If you want to automate ssh login in a shell script you can use "expect".

here is an example: http://bash.cyberciti.biz/security/e...-login-script/
 
Old 01-31-2011, 07:45 AM   #8
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Ashkan_s View Post
If you want to automate ssh login in a shell script you can use "expect".

here is an example: http://bash.cyberciti.biz/security/e...-login-script/
Already tried the script, before posting here. Doesn't work.
The directory /usr/bin/expect is not installed on my system (Linux Novell Suse 10)
 
Old 01-31-2011, 08:02 AM   #9
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Hi,

It would be helpful if you posted the code you are using at the moment.....

Anyway: The below code works on my side:
Code:
#!/bin/bash

username=`whoami`
server="exile"
ssh -XC $username@$server
- exile is the name of one of my servers, substitute it with the valid hostname (or IP) of the machine you want to connect to,
- I do get a message about the -X option, but is is not a show-stopper. You might or might not need the -XC flags.

Hope this helps.
Ok I copied your code:
Code:
#!/bin/bash
username=`whoami`
server="tpi"
ssh -XC $username@$server
Now I get the error:
Quote:
./kdialog.sh: Command not found.
kdialog.sh is the name of my script atm.

Edit: Removed the -XC flags and still the same error
Edit2: When I execute following code, the script echoes the username and server
Code:
username=`whoami`
server="tpi"
echo $username
echo $server
#ssh $username@$server
If I remove the echo's and uncomment the last line, it gives me the ": Name or service not known" error again...

Last edited by c4719929; 01-31-2011 at 08:08 AM.
 
Old 01-31-2011, 08:16 AM   #10
Ashkan_s
Member
 
Registered: Jul 2008
Distribution: Fedora
Posts: 77

Rep: Reputation: 22
Quote:
Originally Posted by c4719929 View Post
Already tried the script, before posting here. Doesn't work.
The directory /usr/bin/expect is not installed on my system (Linux Novell Suse 10)
Can't you install it using YAST or don't you want to install it?

BTW, It exists in opensuse repositories. http://download.opensuse.org/distrib...1-2.7.i586.rpm
 
Old 01-31-2011, 08:25 AM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

./kdialog.sh: Command not found. This tells you the script is not found in the directory you are standing in (bash cannot find kdialog.sh). Use the full path to run the script or cd into the directory were kdialog.sh is.

Just in case, can you post the output of file kdialog.sh and od -c kdialog.sh

Hope this helps.
 
Old 01-31-2011, 08:42 AM   #12
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Ashkan_s View Post
Can't you install it using YAST or don't you want to install it?

BTW, It exists in opensuse repositories. http://download.opensuse.org/distrib...1-2.7.i586.rpm
If I could install it (don't have the root-password), I have to install it on 50+ pc's. A lot of trouble to get a stupid script to work...
 
Old 01-31-2011, 08:49 AM   #13
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Hi,

./kdialog.sh: Command not found. This tells you the script is not found in the directory you are standing in (bash cannot find kdialog.sh). Use the full path to run the script or cd into the directory were kdialog.sh is.

Just in case, can you post the output of file kdialog.sh and od -c kdialog.sh

Hope this helps.
file kdialog.sh
Quote:
kdialog.sh: Bourne-Again shell script text
od -c kdialog.sh
Code:
0000000   #   !   /   b   i   n   /   b   a   s   h  \r  \n   u   s   e
0000020   r   n   a   m   e   =   `   w   h   o   a   m   i   `  \r  \n
0000040   s   e   r   v   e   r   =   "   t   p   i   "  \r  \n   s   s
0000060   h       $   u   s   e   r   n   a   m   e   @   $   s   e   r
0000100   v   e   r
0000103
Btw: I'm in the directory the script is in when I execute it.

Last edited by c4719929; 01-31-2011 at 08:53 AM.
 
Old 01-31-2011, 08:54 AM   #14
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The output of the od command tells me that the kdialog.sh is not a normal linux file. The file terminator is wrong, \r \n => indicates a dos/windows file. \n \n would point to a linux file. That is why your script won't execute.

How are you creating the script?

Hope this helps.
 
2 members found this post helpful.
Old 01-31-2011, 09:00 AM   #15
c4719929
LQ Newbie
 
Registered: Jan 2011
Distribution: Linux Novell Suse 10
Posts: 14

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by druuna View Post
Hi,

The output of the od command tells me that the kdialog.sh is not a normal linux file. The file terminator is wrong, \r \n => indicates a dos/windows file. \n \n would point to a linux file. That is why your script won't execute.

How are you creating the script?

Hope this helps.
Ok the puzzle starts to fall together
I copied the code from my windows pc in a text file and copied that code into a file on my Linux pc.
So if I create a new file and I type it over it should work I hope.
I'll keep you posted!
 
  


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
[SOLVED] Script question: create a shell script in kde to log in on a server with ssh c4719929 Linux - Newbie 1 01-31-2011 03:05 AM
How to execute a ssh script on Linux server from Windows through a bat script? wanna13e Programming 13 10-23-2009 02:41 AM
ssh shell script question ihickman Linux - Newbie 4 02-02-2009 01:10 PM
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM

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

All times are GMT -5. The time now is 06:50 AM.

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