FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS Development

 
 
LinkBack Thread Tools
 
Old 04-13-2011, 01:16 AM
Athmane Madjoudj
 
Default Test-scripts for SSH and MySQL

Hello,

I've attached 4 test-scripts:

Two are for testing MySQL basic DB operations (I've supposed that MySQL
root password is empty which is default in fresh install).


The other are for SSH, one for testing SSH connectivity, the other
(written in Python) create a new user and try to login with SSH.



Best regards.
--
Athmane Madjoudj
RHCE
#!/usr/bin/python
# Author: Athmane Madjoudj <athmanem@gmail.com>

import os,sys

def install_pexpect():
if os.system("rpm -q pexpect") == 0:
return 0
else:
return os.system("yum -y install pexpect")

def ssh_command (user, host, password, command):
import pexpect
ssh_newkey = 'Are you sure you want to continue connecting'
child = pexpect.spawn('ssh -l %s %s %s'%(user, host, command))
i = child.expect([pexpect.TIMEOUT, ssh_newkey, 'password: '])
if i == 0: # Timeout
print child.before, child.after
return None
if i == 1: # SSH does not have the public key. Just accept it.
child.sendline ('yes')
child.expect ('password: ')
i = child.expect([pexpect.TIMEOUT, 'password: '])
if i == 0: # Timeout
print child.before, child.after
return None
child.sendline(password)
child.expect(pexpect.EOF)
print child.before
return child.before

if __name__ == '__main__':
if not os.geteuid()==0:
sys.exit("root privileges are required to run this script")
else:
print "[INFO] Trying to install pexpect ..."
if install_pexpect() != 0:
sys.exit("[FAIL] pexpect installation failed")
print "[INFO] Adding new user ..."
if os.system("userdel sshtest; useradd sshtest && echo sshtest | passwd --stdin sshtest") != 0:
sys.exit("[FAIL] can't add new user")
try:
ssh_command('sshtest','localhost','sshtest','/bin/ls')
except Exception, e:
sys.exit("[FAIL] SSH could not login")
else:
print "[INFO] SSH user login test: PASS"



_______________________________________________
CentOS-devel mailing list
CentOS-devel@centos.org
http://lists.centos.org/mailman/listinfo/centos-devel
 
Old 04-13-2011, 01:57 AM
Athmane Madjoudj
 
Default Test-scripts for SSH and MySQL

On 04/13/2011 02:50 AM, William Chandler wrote:
> Which release?

Tested on CentOS 5.6 and Fedora 14/15, but should be independent.

--
Athmane Madjoudj
RHCE
_______________________________________________
CentOS-devel mailing list
CentOS-devel@centos.org
http://lists.centos.org/mailman/listinfo/centos-devel
 

Thread Tools




All times are GMT. The time now is 09:18 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org