LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-07-2005, 03:32 PM   #1
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Rep: Reputation: 15
Use a shell script to do login and other commands


Hi, i want to know...

if what i'm gonna do is:

1. login to a remote linux server
2. do some system administration work like create directories,
add users...etc

and i want to do the task by a single shell script, or a command...like ssh,
or screen....then, is it possible??

if yes, what should i do?


thanks!!
 
Old 01-07-2005, 03:51 PM   #2
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Sure it's possible.
If were some common task I would just set up the script on the remote server and kick the script off via ssh.

Example of executing a command on a remote system:
ssh <ip_or_DNS_Name> <command>
For example:
ssh 192.168.0.5 ls /etc
will log in and run 'ls /etc'
 
Old 01-07-2005, 04:54 PM   #3
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
thanks!!
but, what if i want to execute multiple commands after login??
do i just use ',' to separate the commands??
 
Old 01-07-2005, 05:02 PM   #4
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
one more question....what if

i want to modify a line in a file after login??? It sounds kind of complicated since
it might not be done by a single command, right??


thanks!
 
Old 01-07-2005, 05:04 PM   #5
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
You will have to use quotes something like this:
ssh 192.168.0.5 "echo first command ;echo second command; echo third command"
 
Old 01-07-2005, 05:08 PM   #6
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
hold on....but when i ssh, i need to provide login and password, right??
 
Old 01-07-2005, 05:54 PM   #7
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
what i mean was....i want my script(or ssh command?) to do the login for me and i
dont' need to manually type the password myself...is it possible?
 
Old 01-08-2005, 09:58 AM   #8
caps_phisto
Member
 
Registered: Sep 2004
Location: NH
Distribution: FC6, FC1-4, RH9, Gentoo 2006.0/1, Slackware 10.1/2,11, Vector SOHO 5.0.1
Posts: 237

Rep: Reputation: 30
That can be done.

On your local machine (i.e. the one you would issue the ssh command on). Make a script that looks like this

Code:
 #!/bin/sh
ssh <ip_address||DNS Name> -u <remote username> -p <remote user passwword> <remote system commnds>
Then just chmod 755 the script and run it.

Hope this helps.

PS- If you do write a script like the one above make sure you are the ONLY persone who can read it . As the "<remote user password>" is saved in clear text in that file.
 
Old 01-10-2005, 07:35 PM   #9
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
what about the prompt like this:
root@host:/usr/# ssh 192.168.1.127
The authenticity of host '192.168.1.127 (192.168.1.127)' can't be established.
RSA key fingerprint is e2:59:6f:fc:33:0b:a9:42:21:cd:0b:f9:53:77:63:bc.
Are you sure you want to continue connecting (yes/no)?


anyone knows how to automatically provide a "yes" for this RSA authentication
in the ssh command, or i need to do it in a script??

thanks!

Jimmy
 
Old 01-10-2005, 11:36 PM   #10
Blinker_Fluid
Member
 
Registered: Jul 2003
Location: Clinging to my guns and religion.
Posts: 682

Rep: Reputation: 63
Quote:
Originally posted by jpan
what about the prompt like this:
root@host:/usr/# ssh 192.168.1.127
The authenticity of host '192.168.1.127 (192.168.1.127)' can't be established.
RSA key fingerprint is e2:59:6f:fc:33:0b:a9:42:21:cd:0b:f9:53:77:63:bc.
Are you sure you want to continue connecting (yes/no)?


anyone knows how to automatically provide a "yes" for this RSA authentication
in the ssh command, or i need to do it in a script??

thanks!

Jimmy
You only have to do that once. After that it already has it in your ~/.ssh/know_hosts file. If you are automating this you might want to look into ssh login without a password.
 
Old 01-11-2005, 06:15 PM   #11
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
Automatically pass the Host Key Verification

but i need to do it automatically even if it's the first time i ssh to the host.
is there any solutions?


thanks!

Jimmy
 
Old 01-11-2005, 06:24 PM   #12
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
The solution:

1. ssh into each of the hosts yourself once. THen you can run your script and that the 'yes/no' prompt will not appear again.
2. setup ssh keys

Honestly, I would recommend with #2 as it is more secure. You don't want to be providing your userame/password in the script.

-twantrd
 
Old 01-11-2005, 06:47 PM   #13
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
i can't use #1.....so could you tell me how to do #2??
I'm using Debian Libranet linux,
thanks a lot!
 
Old 01-11-2005, 06:59 PM   #14
jpan
Member
 
Registered: Aug 2004
Distribution: Debian Libranet
Posts: 69

Original Poster
Rep: Reputation: 15
Hi Caps_phistro, i used the following command but it didn't work:

$ ssh xx.xx.xx.136 -u root -p xxxx ls

ssh: illegal option -- u
Usage: ssh [options] host [command]
Options:
-l user Log in using this user name.
-n Redirect input from /dev/null.
-F config Config file (default: ~/.ssh/config).
-A Enable authentication agent forwarding.
-a Disable authentication agent forwarding (default).
-X Enable X11 connection forwarding.
-x Disable X11 connection forwarding (default).
-i file Identity for public key authentication (default: ~/.ssh/identity)
-t Tty; allocate a tty even if command is given.
-T Do not allocate a tty.
-v Verbose; display verbose debugging messages.
Multiple -v increases verbosity.
-V Display version number only.
-P Don't allocate a privileged port.
-q Quiet; don't display any warning messages.
-f Fork into background after authentication.
-e char Set escape character; ``none'' = disable (default: ~).
-c cipher Select encryption algorithm
-m macs Specify MAC algorithms for protocol version 2.
-p port Connect to this port. Server must be on the same port.
-L listen-port:hostort Forward local port to remote address
-R listen-port:hostort Forward remote port to local address
These cause ssh to listen for connections on a port, and
forward them to the other side by connecting to hostort.
-D port Enable dynamic application-level port forwarding.
-C Enable compression.
-N Do not execute a shell or command.
-g Allow remote hosts to connect to forwarded ports.
-1 Force protocol version 1.
-2 Force protocol version 2.
-4 Use IPv4 only.
-6 Use IPv6 only.
-o 'option' Process the option as if it was read from a configuration file.
-s Invoke command (mandatory) as SSH2 subsystem.
-b addr Local IP address.
 
Old 01-12-2005, 01:15 AM   #15
twantrd
Senior Member
 
Registered: Nov 2002
Location: CA
Distribution: redhat 7.3
Posts: 1,438

Rep: Reputation: 52
Code:
ssh xx.xx.xx.136 -u root -p xxxx ls
After actually reading this thread more (and not just doing a quick glance) I don't believe you can supply your password this way in ssh. -p flag is actually for port and NOT password. -u doesn't exist either.

Code:
i can't use #1.....so could you tell me how to do #2??
The answer to that is here: http://www.arches.uga.edu/~pkeck/ssh/

-twantrd
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to check in a script whether the shell is login or non login? frankie_DJ Programming 5 09-06-2005 06:01 AM
Commands/Shell script ?? paraiso Linux - Newbie 11 04-21-2005 10:58 AM
Commands from shell script not working Grassie Coetzee Linux - Software 2 03-13-2005 02:31 PM
Shell script login command? chup Linux - General 3 08-24-2003 06:43 PM
telnet login via shell script lethe Linux - General 8 05-13-2002 09:31 AM


All times are GMT -5. The time now is 10:42 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration