Posts

Showing posts with the label existed

Check if a DN on a M$ Active Directory existed

I will use the ssh_client module I wrote ( http://iambusychangingtheworld.blogspot.com/2013/05/manipulate-windows-machines-from-linux.html ) to execute M$ Windows Active Directory command line remotely from my Ubuntu. #! /usr/bin/python import ssh_client def dn_existed (dn, type_of_dn, ssh_client): # type_of_dn is group , ou or user command = 'dsget ' + type_of_dn + ' "' + dn + '"' ssh_client.execute_command(command) if 'succeeded' in ssh_client.return_str: return True return False if __name__ == "__main__":        client = ssh_client.MySSHClient()        client.do_connect()        dn = 'OU=MYOU,DC=MYGENIUS,DC=COM'        if dn_existed(dn, 'ou', client):               print "Existed"        else:               print "Not existed"

Bash - Check if an user existed in Django db

When deploying my Django app  to a server, I want to create a script to create Django superuser. The script will check if the inputed user_name existed, if YES, It will prompt me to change password, if NO, it will create the user for me. I use the mysql command to query the user (auth_user table) from the shell just like the way I did in the previous blog spot ( http://iambusychangingtheworld.blogspot.com/2013/06/bash-check-if-mysql-database-is-existed.html ). create_superuser.sh : #! /bin/bash # $1: db username # $2: db password # $3: db name # $4: admin username cd /home/projects/myproject/ . /home/.venv/myvenv/bin/activate RESULT=`mysql -u $1 -p"$2" --skip-column-names -e "USE '$3';SELECT username FROM auth_user WHERE username='$4'"` if echo "$RESULT" | egrep -q "$4" ; then echo "$4 existed" exec python manage.py changepassword $4 else echo "$4 not existed"  exec python manage.py creat...

Bash - Check if a mysql database existed

I use mysqlshow command to check if a mysql database existed, check_db_existed.sh: #! /bin/bash # $1: db username # $2: db password # $3: db name #RESULT=`mysqlshow -u $1 -p"$2" $3 | grep -v Wildcard | grep -o $3` RESULT=`mysql -u $1 -p"$2" --skip-column-names -e "SHOW DATABASES LIKE '$3'"` if echo "$RESULT" | egrep -q "$3" ; then echo "$3 existed" else echo "$3 not existed" fi And call the script to check if 'mydb' existed, (root is db username and password) : # sh check_db_existed.sh root root mydb

Bash shell to check if a string is existed in another string

The example script to check if 'new_user' of rabbitmq has been created: Note : the double-quote used in  USERS_LIST = ` rabbitmqctl list_users `  is " ` " , not " ' "