LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-06-2007, 07:02 AM   #1
mkhan919
Member
 
Registered: Jan 2007
Location: Valbonne, France
Distribution: Mandriva 2008 (Free)
Posts: 135

Rep: Reputation: 15
Bash script question....


hi,


i have been looking for a way to simply a task for me. What i wish to do is to make a script that connects to a certain number of hosts and executes some commands (mainly to kill the proceses that i have launched on them).
What i do is following:

1) connect to the machine (ssh machinename)
2) give my account password (type the password at the prompt)
3) kill all processes started by me (kill -9 `ps -u myname -o "pid="`)


Now the problem is i have to repeat the same thing for 10 machines and it is a bit irritating since i have to do this every now and then.


What is wish to achieve is a way to automate this process i-e , i just run the script and it should do all this. Problem is everytime i connect using ssh, i have to providing password, typing in the password 10 times is not fun.


So is there a way i can privide the ssh password through the script, i-e instead of asking me, script should pass the password itself.
And , enabling the automatic connection etc. is not an option, since i am not an administrator here and so cannot change the configuration files. I know putting my password in a simple plain text file (script) may not be a good idea from security point of view, but i am using the systems from inside the lan and all systems are well protected at the gateway level so that should not be a problem.

Any suggestiosn on how to do this??

Thanx for your help
 
Old 04-06-2007, 07:12 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
It should not be a problem, but it is. Even if you do connect from inside the LAN, somebody else can do that as well -- nothing is bullet-proof

I think it's rather easy storing the password to a variable (for example) and giving it when asked; a simple loop can do the rest. If I'm not completely mistaken, this site linuxcommand.org has the steps you're asking (if not directly, then indirectly). In addition I've found, using google, a program that you can use to "record" a session -- shortly said you launch the program, it starts "listening", you log on to the machines and do whatever you're supposed to, then log off and stop recording. The idea is like creating a "macro" (though I'm not sure if one could call it a macro). After this, or rather after you've reviewed the "code", the "recorded" thing should be able to do all that by itself, answering to password prompts etc. The bad part is, I can't remember for the life of me what the program was called -- but it's not anything new, it's rather grown-up already.

I'm sure Google finds you more. And remember to check out linuxcommand.org!
 
Old 04-06-2007, 07:12 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
check the tutorial on ssh shared key authenticatoin, should be all you need. also ont that you can pass commands directly via ssh, e.g. "ssh user@box ls -l /tmp"
 
Old 04-06-2007, 07:13 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
the program described above would be expect. and whilst it's a great tool really isn't the right way to solve a problem like this imho. it's also very very easy for automatically recorded expect sessions to go wrong.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script question armandino101 Linux - Newbie 5 10-18-2006 06:32 PM
bash script question edward_scott Linux - Newbie 4 08-26-2006 03:54 PM
Bash script question deiussum Programming 6 08-14-2004 12:43 PM
bash script question djgerbavore Linux - Newbie 3 07-08-2004 04:39 PM
bash script question xscousr Programming 5 07-03-2003 06:04 PM


All times are GMT -5. The time now is 12:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration