LogMeTT.com • Any automated code to replace Mpause?
Page 1 of 1

Any automated code to replace Mpause?

Posted: Mon Jun 19, 2017 2:19 am
by Mokan

Code: Select all

  1.  
  2. ; ***Macro Template to collect Router log****************
  3.  
  4. ; Get current directory
  5. getdir curdir
  6. groupmatchstr1=curdir
  7. groupmatchstr2="\Logs"
  8. strjoin strvar "" 2
  9. changedir strvar
  10. setdir strvar
  11.  
  12. CommandPrompt = '#'
  13. inputbox 'Please enter ZoneID:' 'Zone ID'
  14. ZoneID = inputstr
  15. ;inputbox 'Please enter SiteID:' 'Site ID'
  16. ;SiteID = inputstr
  17. SiteID = ''
  18. inputbox 'Please enter Router name with Router ID:' 'Router Name'
  19. RouterName = inputstr
  20. toupper RouterName RouterName
  21.  
  22. groupmatchstr1=ZoneID
  23. groupmatchstr2=SiteID
  24. groupmatchstr3=RouterName
  25. groupmatchstr4=".log"
  26. strjoin logfile "" 4
  27. ;logfile=strvar
  28.  
  29. groupmatchstr1= logfile
  30. groupmatchstr2= ".tmp"
  31. strjoin tmp_file "" 2
  32. ;tmp_file = strvar
  33.  
  34. ;start logging
  35. logopen logfile 0 0
  36. gettime curtime "------------------------------------%Y-%m-%d %H:%M:%S----------------------------------"
  37. logwrite curtime
  38.  
  39. ;setsync 0
  40.  
  41. sendln
  42.  
  43. wait CommandPrompt
  44. sendln 'set sl=n'
  45.  
  46. wait CommandPrompt
  47. flushrecv
  48. sendln 'sh date'
  49.  
  50. wait CommandPrompt
  51. flushrecv
  52. sendln 'sh timezone'
  53.  
  54. wait CommandPrompt
  55. flushrecv
  56. sendln 'sh ' 'sysinfo'
  57.  
  58. wait CommandPrompt
  59. flushrecv
  60. sendln 'sh ' '-' 'ip allroute'
  61.  
  62. mpause 500
  63. wait CommandPrompt
  64. flushrecv
  65. sendln 'sh ' '-' 'ntp status'
  66.  
  67. wait CommandPrompt
  68. flushrecv
  69. sendln 'sh ' '-' 'sys sm'
  70.  
  71. mpause 500
  72. wait CommandPrompt
  73. flushrecv
  74. sendln 'sh version'
  75.  
  76. pause 5
  77. wait CommandPrompt
  78. sendln 'exit'
  79.  
  80. logclose
  81.  


Above is an example of macro to collect logs from a router. Any idea how to code to make sure that the a command runs completely from one command to another command without using "mpause". Any idea how do i automate it??

Re: Any automated code to replace Mpause?

Posted: Tue Jun 20, 2017 11:40 am
by Trevor
Have you tried just removing the "mpause" lines? If so what does not work when you do?

Re: Any automated code to replace Mpause?

Posted: Wed Jun 21, 2017 1:19 am
by Mokan
Trevor wrote:Have you tried just removing the "mpause" lines? If so what does not work when you do?

The reason i included mpause is that to allow the command before to run completely. Is there any way besides using mpause to get the commands completely executed before jumping into another command while running through macro.

Re: Any automated code to replace Mpause?

Posted: Thu Jun 22, 2017 9:00 am
by Trevor
But you are waiting for the command prompt after the command so therefore the mpause should not be needed i.e. the command prompt should only appear after the command has completed. Hence my previous question.

The wait for command prompt should really have a timeout and detect when a timeout occurs. I would make it a function like this:

Code: Select all

  1. :wait_for_command_prompt
  2.     timeout = 10
  3.     waitln '#'
  4.     if result == 0 then
  5.         messagebox 'timeout waiting for command prompt' 'Error'
  6.         end
  7.     endif
  8.     flushrecv
  9. return

And then instead of

Code: Select all

  1. wait CommandPrompt
use

Code: Select all

  1. call wait_for_command_prompt


Then if you do need a delay you have just one place to put in (in the function).

Re: Any automated code to replace Mpause?

Posted: Thu Jun 29, 2017 5:50 am
by Mokan

Code: Select all

  1.  
  2. ; ***Macro Template to collect Router log****************
  3.  
  4. ; Get current directory
  5. getdir curdir
  6. groupmatchstr1=curdir
  7. groupmatchstr2="\Logs"
  8. strjoin strvar "" 2
  9. changedir strvar
  10. setdir strvar
  11.  
  12. ;CommandPrompt = '#'
  13. inputbox 'Please enter ZoneID:' 'Zone ID'
  14. ZoneID = inputstr
  15. ;inputbox 'Please enter SiteID:' 'Site ID'
  16. ;SiteID = inputstr
  17. SiteID = ''
  18. inputbox 'Please enter Router name with Router ID:' 'Router Name'
  19. RouterName = inputstr
  20. toupper RouterName RouterName
  21.  
  22. groupmatchstr1=ZoneID
  23. groupmatchstr2=SiteID
  24. groupmatchstr3=RouterName
  25. groupmatchstr4=".log"
  26. strjoin logfile "" 4
  27. ;logfile=strvar
  28.  
  29. groupmatchstr1= logfile
  30. groupmatchstr2= ".tmp"
  31. strjoin tmp_file "" 2
  32. ;tmp_file = strvar
  33.  
  34. ;start logging
  35. logopen logfile 0 0
  36. gettime curtime "------------------------------------%Y-%m-%d %H:%M:%S----------------------------------"
  37. logwrite curtime
  38.  
  39. ;setsync 0
  40.  
  41.  
  42. sendln
  43.  
  44. :wait_for_command_prompt
  45.     mpause 1000
  46.     CommandPrompt = '#'
  47.     wait CommandPrompt
  48. return
  49.  
  50. sendln 'set sl=n'
  51. call wait_for_command_prompt
  52.  
  53. flushrecv
  54. sendln 'sh date'
  55. call wait_for_command_prompt
  56.  
  57. flushrecv
  58. sendln 'sh timezone'
  59. call wait_for_command_prompt
  60.  
  61. flushrecv
  62. sendln 'sh ' 'sysinfo'
  63. call wait_for_command_prompt
  64.  
  65. flushrecv
  66. sendln 'sh ' '-' 'ip allroute'
  67. call wait_for_command_prompt
  68.  
  69. flushrecv
  70. sendln 'sh ' '-' 'ntp status'
  71. call wait_for_command_prompt
  72.  
  73. flushrecv
  74. sendln 'sh ' '-' 'sys sm'
  75. call wait_for_command_prompt
  76.  
  77. flushrecv
  78. sendln 'sh version'
  79. call wait_for_command_prompt
  80.  
  81. flushrecv
  82. sendln 'sh ' '-' 'sys soft a:/primary/boot.ppc'
  83. call wait_for_command_prompt
  84.  
  85. flushrecv
  86. sendln 'sh ' '-' 'sys soft a:/secondar/boot.ppc'
  87. call wait_for_command_prompt
  88.  
  89. flushrecv
  90. sendln 'sf 9'
  91.  
  92. wait 'Press Y to clear boot statistics (any other key to cancel) :'
  93. flushrecv
  94. sendln ''
  95. call wait_for_command_prompt
  96.  
  97. flushrecv
  98. sendln 'cd ' "a:/audlog"
  99. call wait_for_command_prompt
  100.  
  101. flushrecv
  102. sendln 'df'
  103. call wait_for_command_prompt
  104.  
  105. ; parse audit log file name
  106. strdim aud_tmp 999
  107. i=0
  108. filecopy logfile tmp_file
  109. fileopen fhandle tmp_file 0
  110. while 1
  111.     filereadln fhandle line
  112.     if result=1 then
  113.         break
  114.     endif
  115.     ;messagebox line 'temp.log'
  116.     strscan line 'AUD'
  117.     if result > 0 then
  118.     strcopy line 1 6 aud_tmp[i]
  119.     ;messagebox aud_tmp[i] 'audlog'
  120.     i=i+1
  121.     result=0
  122.     endif
  123. endwhile
  124. fileclose fhandle
  125. filedelete tmp_file
  126.  
  127. ; Cat audit log
  128. groupmatchstr1="cat "
  129. groupmatchstr3=".log"
  130. j=0
  131. strdim aud 999
  132. if i>0 then
  133.     for j 0 i-1
  134.     groupmatchstr2=aud_tmp[j]
  135.     strjoin aud[j] "" 3
  136.     sendln aud[j]
  137.     pause 1
  138.     next
  139. endif
  140. call wait_for_command_prompt
  141.  
  142. flushrecv
  143. sendln 'sh ' '-' 'audit locallog'
  144. call wait_for_command_prompt
  145.  
  146. flushrecv
  147. sendln 'cd a:/'
  148. call wait_for_command_prompt
  149.  
  150. flushrecv
  151. sendln 'cat ' 'partial1.dmp'
  152. call wait_for_command_prompt
  153.  
  154. flushrecv
  155. sendln 'cat ' 'partial2.dmp'
  156. call wait_for_command_prompt
  157.  
  158. flushrecv
  159. sendln 'cat ' 'partial3.dmp'
  160. call wait_for_command_prompt
  161.  
  162. flushrecv
  163. sendln 'sh ' '-' 'ip netaddr'
  164. call wait_for_command_prompt
  165.  
  166. flushrecv
  167. sendln 'sh ' '-' 'ip addr'
  168. call wait_for_command_prompt
  169.  
  170. flushrecv
  171. sendln 'sh ' '-' 'sys stat ' '-' 'port'
  172. call wait_for_command_prompt
  173.  
  174. flushrecv
  175. sendln 'sh ' '-' 'sys stat ' '-' 'path'
  176. call wait_for_command_prompt
  177.  
  178. flushrecv
  179. sendln 'sh ' '-' 'path config'
  180. call wait_for_command_prompt
  181.  
  182. flushrecv
  183. sendln 'sh ' '-' 'po conf'
  184. call wait_for_command_prompt
  185.  
  186. flushrecv
  187. sendln 'sh ' '-' 'po queuepri'
  188. call wait_for_command_prompt
  189.  
  190. flushrecv
  191. sendln 'sh ' '-' 'po QueueStatistics'
  192. call wait_for_command_prompt
  193.  
  194. flushrecv
  195. sendln 'su ' 'mu'
  196. call wait_for_command_prompt
  197.  
  198. flushrecv
  199. sendln 'su ' 'drt'
  200. call wait_for_command_prompt
  201.  
  202. flushrecv
  203. sendln 'sh ' '-' 'pa ma'
  204. call wait_for_command_prompt
  205.  
  206. flushrecv
  207. sendln 'sh ' '-' 'ccgw conf'
  208. call wait_for_command_prompt
  209.  
  210. flushrecv
  211. sendln 'cd ' 'a:/primary'
  212. call wait_for_command_prompt
  213.  
  214. sendln 'cat config.log'
  215. call wait_for_command_prompt
  216.  
  217. flushrecv
  218. sendln 'cat capture.cfg'
  219. call wait_for_command_prompt
  220.  
  221. flushrecv
  222. sendln 'cat boot.cfg'
  223. call wait_for_command_prompt
  224.  
  225. flushrecv
  226. sendln 'cat staticrp.cfg'
  227. call wait_for_command_prompt
  228.  
  229. flushrecv
  230. sendln 'cat xgsn.cfg'
  231. call wait_for_command_prompt
  232.  
  233. flushrecv
  234. sendln 'cd ' 'a:/secondar'
  235. call wait_for_command_prompt
  236.  
  237. flushrecv
  238. sendln 'cat config.log'
  239. call wait_for_command_prompt
  240.  
  241. flushrecv
  242. sendln 'cat capture.cfg'
  243. call wait_for_command_prompt
  244.  
  245. flushrecv
  246. sendln 'cat boot.cfg'
  247. call wait_for_command_prompt
  248.  
  249. flushrecv
  250. sendln 'cat staticrp.cfg'
  251. call wait_for_command_prompt
  252.  
  253. flushrecv
  254. sendln 'cat xgsn.cfg'
  255. call wait_for_command_prompt
  256.  
  257. flushrecv
  258. sendln 'sh ' '-' 'vrrp conf'
  259. call wait_for_command_prompt
  260.  
  261. flushrecv
  262. sendln 'sh ' '-' 'NAT conf'
  263. call wait_for_command_prompt
  264.  
  265. flushrecv
  266. sendln 'sh ' '-' 'NAT sessions'
  267. call wait_for_command_prompt
  268.  
  269. flushrecv
  270. sendln 'sh ' '-' 'pim conf'
  271. call wait_for_command_prompt
  272.  
  273. flushrecv
  274. sendln 'sh ' '-' 'pim mcastgrouplim'
  275. call wait_for_command_prompt
  276.  
  277. flushrecv
  278. sendln 'sh ' '-' 'pim mcastgrouplimrp'
  279. call wait_for_command_prompt
  280.  
  281. flushrecv
  282. sendln 'sh ' '-' 'pim rps'
  283. call wait_for_command_prompt
  284.  
  285. flushrecv
  286. sendln 'sh ' '-' 'pim rt'
  287. call wait_for_command_prompt
  288.  
  289. flushrecv
  290. sendln 'sh ' '-' 'pim rt long'
  291. call wait_for_command_prompt
  292.  
  293. flushrecv
  294. sendln 'sh ' '-' 'pim staticrp'
  295. call wait_for_command_prompt
  296.  
  297. flushrecv
  298. sendln 'sh ' '-' 'pim staticrp summary'
  299. call wait_for_command_prompt
  300.  
  301. flushrecv
  302. sendln 'sh ' '-' 'pim neigh'
  303. call wait_for_command_prompt
  304.  
  305. flushrecv
  306. sendln 'sh ' '-' 'mip igmp'
  307. call wait_for_command_prompt
  308.  
  309. flushrecv
  310. sendln 'sh ' '-' 'mip fc'
  311. call wait_for_command_prompt
  312.  
  313. flushrecv
  314. sendln 'sh ' '-' 'mip vrrp'
  315. call wait_for_command_prompt
  316.  
  317. flushrecv
  318. sendln 'sh ' '-' 'mip rpf 10.1.253.9'
  319. call wait_for_command_prompt
  320.  
  321. flushrecv
  322. sendln 'sh ' '-' 'mip rpf 10.1.253.17'
  323. call wait_for_command_prompt
  324.  
  325. flushrecv
  326. sendln 'sh ' '-' 'fr dlcistat'
  327. call wait_for_command_prompt
  328.  
  329. flushrecv
  330. sendln 'sh ' '-' 'ospf ns'
  331. call wait_for_command_prompt
  332.  
  333. flushrecv
  334. sendln 'sh ' '-' 'pa connst'
  335. call wait_for_command_prompt
  336.  
  337. flushrecv
  338. sendln 'sh ' '-' 'fr mfrdispstat'
  339. call wait_for_command_prompt
  340.  
  341. flushrecv
  342. sendln 'sh ' '-' 'fr QueueStatistics'
  343. call wait_for_command_prompt
  344.  
  345. flushrecv
  346. sendln 'sh ' '-' 'cwr status'
  347. call wait_for_command_prompt
  348.  
  349. flushrecv
  350. sendln 'sh ' '-' 'cwr conf'
  351. call wait_for_command_prompt
  352.  
  353. flushrecv
  354. sendln 'sh ' '-' 'pa WanCounters'
  355. call wait_for_command_prompt
  356.  
  357. flushrecv
  358. sendln 'sh ' '-' 'pa conncounters'
  359. call wait_for_command_prompt
  360.  
  361. flushrecv
  362. sendln 'sh ' '-' 'fr MfrAvcQueS'
  363. call wait_for_command_prompt
  364.  
  365. flushrecv
  366. sendln 'sh ' '-' 'fr VcQueStats 16'
  367. call wait_for_command_prompt
  368.  
  369. flushrecv
  370. sendln 'sh ' '-' 'fr VcQueStats 17'
  371. call wait_for_command_prompt
  372.  
  373. flushrecv
  374. sendln 'sh ' '-' 'sys stat ' '-' 'fr'
  375. call wait_for_command_prompt
  376.  
  377. flushrecv
  378. sendln 'sh lmi'
  379. call wait_for_command_prompt
  380.  
  381. flushrecv
  382. sendln 'sh ' '-' 'ip bfds'
  383. call wait_for_command_prompt
  384.  
  385. flushrecv
  386. sendln 'sh ' '-' 'SCH bfdevent'
  387. call wait_for_command_prompt
  388.  
  389. flushrecv
  390. sendln 'sh ' '-' 'ipdv STAT'
  391. call wait_for_command_prompt
  392.     
  393. sendln 'end'
  394.  
  395. logclose
  396.  


Above are the new set of codes. My concern is that whenever i remove mpause from the function the length of logs collected are shorter which highlights some commands needed timeout to fully completed. Thus if im using this function on other routers which needed longer pause time how do i overcome it. Is there any commands would help to fix this problem without using mpause.