Jump to content

Batch files for ssh/linux...


Recommended Posts

Posted

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. :).

Posted

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.

 

ssh user@system /usr/bin/somescript.sh

 

Or run the commands over SSH one after the other.

 

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

  • Thanks 1
Posted
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:

 

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

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...