+ Reply to Thread
Results 1 to 5 of 5

Thread: Batch files for ssh/linux...

  Share/Bookmark
  1. #1

    Reputation

    Join Date
    Nov 2007
    Posts
    555
    Thank Post
    3
    Thanked 3 Times in 3 Posts
    Rep Power
    7

    Default Batch files for ssh/linux...

    Hi.
    Does anyone know of a way to run a script that'll auto connect to a server via SSH (smoothwall), login and then perform a few commands, then close the SSH session.

    Thanks in advance all. .

  2. #2

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    Geoff's Avatar
    Join Date
    Jun 2005
    Location
    Fylde, Lancs, UK.
    Posts
    10,833
    Blog Entries
    1
    Thank Post
    97
    Thanked 392 Times in 337 Posts
    Rep Power
    101

    Default

    First off, you need to swap ssh keys with the remote system so you can login without a password prompt.

    HOWTO: set up ssh keys

    At that point you can either run a single SSH command to run the script on the remote system.

    Code:
    ssh user@system /usr/bin/somescript.sh
    
    Or run the commands over SSH one after the other.

    Code:
    ssh user@system /usr/games/fortune | /sbin/wall
    ssh user@system /sbin/reboot
    

  3. Thanks to Geoff from:

    tom_newton (13-11-2008)

  4. #3

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation

    Join Date
    Feb 2006
    Location
    Derbyshire
    Posts
    1,374
    Thank Post
    175
    Thanked 207 Times in 168 Posts
    Rep Power
    53

    Default

    If you mean from Windows to the Linux machine, I'd just do it with PLink the command line driven aspect of Putty...

    Using the command-line connection tool Plink

    Should do everything quite happily.

  5. 2 Thanks to OutToLunch:

    tom_newton (13-11-2008), webman (12-11-2008)

  6. #4

    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    dhicks's Avatar
    Join Date
    Aug 2005
    Location
    Alton, Hampshire
    Posts
    3,483
    Thank Post
    620
    Thanked 396 Times in 342 Posts
    Rep Power
    101

    Default

    Quote Originally Posted by boomam View Post
    Does anyone know of a way to run a script that'll auto connect to a server via SSH (smoothwall), login and then perform a few commands, then close the SSH session.
    As pointed out above, on Windows plink connecting with a key file should do it. I've actually had occasion to write a utility that does pretty much what you describe above, for which I used Python:

    Code:
    for fileLine in os.popen("PuTTY\\plink -batch -i PuTTY\\xenConsole.ppk root@" + dirName + " cat /proc/mdstat").readlines():
    	line = fileLine[:-1]
    	reResult =  re.search(" *(.*) blocks \[(.*)/(.*)\] \[(.*)\]", line)
    	if reResult:
    		RAIDState = reResult.group(4)
    

    The above connects to the server and gets the state of the mdadm RAID array, sorting through the answer with a regular expression to parse out the data needed.

    --
    David Hicks

  7. Thanks to dhicks from:

    tom_newton (13-11-2008)

  8. #5


    Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation Reputation
    tom_newton's Avatar
    Join Date
    Sep 2006
    Location
    Leeds
    Posts
    2,489
    Thank Post
    272
    Thanked 342 Times in 259 Posts
    Rep Power
    78

    Default

    Thanks for the answers folks... now I am wondering what the OP was wanting and how we might officially support what he's after?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Rename a batch of files all at once.
    By Kyle in forum How do you do....it?
    Replies: 10
    Last Post: 19-11-2009, 06:31 AM
  2. Running batch files in vista
    By Kained in forum Windows Vista
    Replies: 6
    Last Post: 04-09-2007, 02:25 PM
  3. numbers and batch files
    By russdev in forum Windows
    Replies: 4
    Last Post: 19-11-2005, 09:51 PM
  4. Blocking Batch Files using Group Policy in Server 2003
    By markwilliamson2001 in forum Windows
    Replies: 13
    Last Post: 04-10-2005, 05:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts