Linux script for multiple box login.


 
Thread Tools Search this Thread
Operating Systems Linux Linux script for multiple box login.
# 1  
Old 02-24-2014
Linux Linux script for multiple box login.

Hello! We currently use a SecureCRT .vbs script which automates logging into multiple boxes to run a few commands. However, I'd like to have something run in Linux vs. our emulator. Below is my objective Smilie:

Our current .vbs script will look at an IP list .txt file on our PC, then login to each IP within the .txt, and execute the following:

Code:
ssh router1@[IP Address]
su - root     #prompted for PW.
su - secadmin2    #We don't get prompted for secadmin2 password :)
cd .ssh
cp authorized_keys authorized_keys_bkup
cat /app2/.ssh/Vkey >> authorized_keys
exit
exit
cd .ssh
cp Vkey Vkey.orig
cat Vkey >> authorized_keys
rm /app2/.ssh/Vkey
exit

Again, the script must prompt for root password (only once since all root PW's will be the same), and loop commands above for all IP's found on file. Can anyone help with this? I know many coders here can whip something right quick as you have in the past.....your assistance is greatly appreciated!


I forgot to add vba code were currently using on SecureCRT:

Code:
# $language = "VBScript"
# $interface = "1.0"
'-------------------------------------------------------------------------------
' BIRDBOYEE
'-------------------------------------------------------------------------------
Sub Main
'------------------------------------------------------------
Dim ObjFSO, InitFSO, Wscript
sDir = "D:\Documents and Settings\BIRDBOYEE"
Set ObjFSO = CreateObject("UserAccounts.CommonDialog")
ObjFSO.Filter = "Text Files|*.txt|All Files|*.*"
ObjFSO.FilterIndex = 1
ObjFSO.InitialDir = sDir
InitFSO = ObjFSO.ShowOpen

If InitFSO = False Then 
  Exit Sub
End If
'-----------------------------------------------------------
Const ForReading = 1

  Dim fso, file, str
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set file = fso.OpenTextFile(ObjFSO.FileName, ForReading, False)

  crt.Screen.Synchronous = True
   crt.Screen.Send "grep rtr /etc/hosts" & vbCr
   crt.Screen.WaitForString ">"
'-----------------------------------------------------------   
 Do While file.AtEndOfStream <> True
  str = file.Readline
 
  crt.Screen.Send "ssh root@" & str & vbCr
  crt.Screen.WaitForString ">"
   crt.Screen.Send "su - root" & vbCr 
  crt.Screen.WaitForString ">"
    crt.Screen.Send "password" & vbCr    '#Manually enter password here.
  crt.Screen.WaitForString ">"
    crt.Screen.Send "su - secadmin2" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "cd .ssh" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "cp authorized_keys authorized_keys_bkup" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "cat /app2/.ssh/Vkey >> authorized_keys" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "exit" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "exit" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "cd .ssh" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "cp Vkey Vkey.orig" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "cat Vkey >> authorized_keys" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "rm /app2/.ssh/Vkey" & vbCr
  crt.Screen.WaitForString ">"
    crt.Screen.Send "exit" & vbCr
  
   Loop
'----------------------------------------------------------
 crt.Screen.Synchronous = False
'----------------------------------------------------------
End Sub


Last edited by birdboyee; 02-25-2014 at 08:43 PM..
# 2  
Old 03-18-2014
The ususal solution is to set up trusted PPK for your host/id and the target host/id's. With password-free login, you can ssh and run what you want. Also 'parallel' has features designed to support multiple parallel sessions with logging as if they were sequential, to kill the latency.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Remote login UNIX box from java passing parameters to the custom script called in the profile

Hello Good Day / Guten Tag.... I have to login the server and the user profile contains some scripts which need the inputs to be taken from the keyboard. So I use the method to conn.authenticateWithKeyboardInteractive(username, new InteractiveCallback() { public String... (1 Reply)
Discussion started by: Sanalkumaran
1 Replies

2. How to Post in the The UNIX and Linux Forums

Copying , renaming the file from windox box and ftp to Linux box

Hello my dear friends, Two file are auto generated from mon - fri at different directories on same windows box.Every day i have to copy the file, rename it (specific name)and ftp it to linux box specified directory. is it possible to automate this process,If yes this has to be done from windows... (1 Reply)
Discussion started by: umesh yadav
1 Replies

3. Red Hat

How to access redhat Linux box graphically from windows box?

Hi I have a linux box and need to access from windows graphically # uname -a Linux pc-l416116 2.6.18-155.el5 #1 SMP Fri Jun 19 17:06:47 EDT 2009 i686 i686 i386 GNU/Linux What components do I need to install on Linux and windows to do that? TIA (6 Replies)
Discussion started by: magnus29
6 Replies

4. Shell Programming and Scripting

Need a Script , we are having Linux box

HI I need help on developing 2 scripts as mentioned below. One way process -> We can get files of 01, 02, 07 record types (Here we need to keep a filter to read the first 2 characters in the file and if they are equal to 01 or 02 we need to do the below process and if its 07 we need to... (2 Replies)
Discussion started by: nanduedi
2 Replies

5. Shell Programming and Scripting

Issues for script that login to a unix box

Hi, I have a script that should login to a different box then the box that i am in and run the commands. I have the script sample below that logins to a unix box and get the files .Looks like ls-lrt command is not running or its wrongly used. #!/bin/bash # Ask the user for build month... (5 Replies)
Discussion started by: learninguser235
5 Replies

6. Shell Programming and Scripting

Shell script to login into multiple linux boxes

I have requirement to login into a multiple linux boxes by running the shell script in a single linux box and to find the count of files in a specific folder in each box and log them in a log file in the box where i m runnning the script. Box names will be stored in a text file host.txt. Please... (2 Replies)
Discussion started by: Mani2512
2 Replies

7. Linux

How to find remote Linux box login account without login in to that box?

Hi, How to find remote Linux box login account without login in to that box? I don't have login account at my remote Linux box. But I need who are all having login account. How do I findout? Thanks, --Muthu. (3 Replies)
Discussion started by: Muthuselvan
3 Replies

8. Shell Programming and Scripting

script to monitor mount points on linux box

Hi, the following shell script is not working on linux box sugeestions appreciated. FILE1=/tmp/check1.txt FILE2=/tmp/check2.txt df -k | awk '{if (NR != 1) print $5 $6}' > ${FILE1} awk -F"%" '{if ($1 > 90) print "Warning: Filesystem " $2 " over 90% threshold (" $1 "%)"}' ${FILE1} >... (7 Replies)
Discussion started by: prakash.gr
7 Replies

9. Linux

Multiple linux distros in one box

Hi, This will be my first time to install 5 distros in one box, the ff. are: openSUSE 11, openSUSE11.1, Ubuntu 8.04, Ubuntu 8.10, Fedora 10 Now, I'm confused how would I partitioned my hard disk with a capacity of 80Gb where there is only one swap and no idea yet how to play with boot... (2 Replies)
Discussion started by: etcpasswd
2 Replies

10. Shell Programming and Scripting

Script to Reboot a linux box from a windows box

HI All, I need a script to reboot a linux box from a windows box. The script needs to run automatically whenever a sitescope alerts with an error message. Have searched for this in the forums, but could not get something relative. Pls. let me know the various alternatives we have to do... (2 Replies)
Discussion started by: Crazy_murli
2 Replies
Login or Register to Ask a Question