Monday, August 24, 2015

Python script to copy image

#!/usr/bin/env python
import os
import re
import sys

def get_label(cmd):
  label_full = os.popen(cmd).read()
  print label_full
  label_group = re.match(r'.*(BLD.*)',label_full,flags=0)
  label = label_group.group(1)
  return label
def get_image():
  label = get_label(cmd)
  if (target == 'edison'):
      cmd_image = "\/auto\/binos-tools\/bin\/mcpre_abs image -l " + label + " -u EDISON_SUPER_NOVA"
  elif (target == 'katana'):
      cmd_image = "\/auto\/binos-tools\/bin\/mcpre_abs image -l " + label + " -u KATANA_SUPER_NOVA"
  image = str(os.popen(cmd_image).read())
  image = image.split('\n')
  image = str(image[0])
  print image
  if (target == 'edison'):
      image_name = re.match(r'.*(cat3k.*)',image).group(1)
  elif (target == 'katana'):
      image_name = re.match(r'.*(ct5760.*)',image).group(1)
  return image,image_name
  #return image
def copy_tftp(tftp_loc):
  #image = get_image()
  image,image_name = get_image()
  touch_file = "touch " + tftp_loc + image_name
  copy_cmd = "cp " + image + ' ' + tftp_loc
  perm_cmd = "chmod 777 " + tftp_loc + image_name
  print touch_file
  print perm_cmd
  print copy_cmd
  os.system(touch_file)
  os.system(perm_cmd)
  os.system(copy_cmd)
if __name__ == "__main__":
    cmdargs = list(sys.argv)
    argsLen = len(sys.argv)
    print argsLen
    print cmdargs
    if (argsLen == 4 and (cmdargs[2] == 'edison' or cmdargs[2] == 'katana')):
        tftp_loc = cmdargs[1]
        target = cmdargs[2]
        branch = cmdargs[3]
        print target
        if (tftp_loc == '.'):
            print "Getting current TFTP Location..."
            tftp_loc = str(os.popen('pwd').read())
            tftp_loc = tftp_loc.split('\n')
            tftp_loc = str(tftp_loc[0])+'/'
        print tftp_loc
        if (branch == 'dev'):
            cmd = str("\/auto\/binos-tools\/bin\/mcpre_abs list -b polaris_dev -m {\"s2s accepted\",\"polarispublished\",\
"creg-ready-edison\",\"creg-ready-katana\"} -n 1 -c Daily -s DONE")
        elif (branch == 'throttle'):
            cmd = str("\/auto\/binos-tools\/bin\/mcpre_abs list -b v161_0_throttle -m {\"s2s accepted\",\"polarispublished
\",\"creg-ready-edison\",\"creg-ready-katana\"} -n 1 -c Daily -s DONE")
        else:
            print "Please give polaris_dev or v161_0_throttle branch"
        copy_tftp(tftp_loc)
    else:
        print "Please provide required/Correct Parameters"

Sunday, August 23, 2015

Create alias in windows

1. Create "aliases.bat" file with below aliases and save it in the dektop

@echo off
cls
Set Sleep=0

doskey mc1=C:\wl\wl_vista_7.exe reassoc C4:14:3C:F3:10:FA
doskey ma1=C:\wl\wl_vista_7.exe reassoc F8:C2:88:83:EC:FA
doskey ma2=C:\wl\wl_vista_7.exe reassoc C4:14:3C:29:2F:4A
doskey mc2=C:\wl\wl_vista_7.exe reassoc 08:1F:F3:E0:2D:9A
doskey ma3=C:\wl\wl_vista_7.exe reassoc 08:CC:68:B4:06:1A
doskey ma32=C:\wl\wl_vista_7.exe reassoc A8:0C:0D:DB:C3:B0
doskey nmc12=C:\wl\wl_vista_7.exe reassoc c800.8460.6eb0
doskey nma1=C:\wl\wl_vista_7.exe reassoc c800.8460.7a70

2. Open "Cmd" and Execute below command:

C:\wl>C:\Users\test\Desktop\aliases.bat

3. Type any of the aliases created in step 1 like mc1, ma1, etc ..

Useful reference: http://superuser.com/questions/49170/create-an-alias-in-windows-xp






Monday, August 3, 2015

Restart_wifi_NIC in Win 7

netsh interface set interface "Wireless Network Connection" admin=DISABLED
timeout 2
netsh interface set interface "Wireless Network Connection" admin=ENABLED

Create directory with current date

[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>ls -lrt /auto/tftp-sanity-testbed-infra/wireless_accounting_logs/
total 12
drwxrwxrwx 2 srikragh eng 4096 Jul 24 22:26 20150723/
drwxrwxrwx 2 srikragh eng 4096 Aug  1 01:06 run2/
drwxrwxrwx 2 srikragh eng 4096 Aug  2 15:13 run1/
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>mkdir "/auto/tftp-sanity-testbed-infra/wireless_accounting_logs/`date +%Y%m%d`"
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>ls -lrt /auto/tftp-sanity-testbed-infra/wireless_accounting_logs/            total 16
drwxrwxrwx 2 srikragh eng 4096 Jul 24 22:26 20150723/
drwxrwxrwx 2 srikragh eng 4096 Aug  1 01:06 run2/
drwxrwxrwx 2 srikragh eng 4096 Aug  2 15:13 run1/
drwxr-xr-x 2 srikragh eng 4096 Aug  3 15:12 20150803/
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>
[bgl-ads-843:/auto/tftp-blr-users1/srikragh]>

Below is TCL code for the same:

        set GA(tftp_path) /auto/tftp-blr-users1/wireless_accounting
set GA(timestamp) [exec date +%Y%m%d%H%M%S]
file mkdir $GA(tftp_path)/log_$GA(timestamp)
exec /bin/sh -c "chmod 777 $GA(tftp_path)/log_$GA(timestamp)"

Sample output

drwxrwxrwx 2 srikragh  eng       4096 Aug  3 23:01 log_20150803101713/
drwxrwxr-x 2 srikragh  eng       4096 Aug  3 23:04 log_20150803103459/
drwxrwxrwx 2 srikragh  eng       4096 Aug  3 23:20 log_20150803104920/