{"id":2405,"date":"2017-12-08T09:33:19","date_gmt":"2017-12-08T09:33:19","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/?p=2405"},"modified":"2020-01-09T10:01:58","modified_gmt":"2020-01-09T10:01:58","slug":"shell-script-to-run-x-times","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/shell-script-to-run-x-times\/","title":{"rendered":"Shell script to run x times"},"content":{"rendered":"<p><strong>rajeshkumar created the topic: shell script to run x times<\/strong><br \/>\nProblem:<\/p>\n<p>First i need to cd to this directory $SWDIR\/util<br \/>\nSecond i need to run the following either 4 times or 20 times<\/p>\n<p>.\/swadm add_process 1 BG Y<\/p>\n<p>how can i put this in a script<\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @<a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\"> twitter.com\/RajeshKumarIn<\/a><\/p>\n<p><strong>rajeshkumar replied the topic: Re:shell script to run x times<\/strong><br \/>\nSolution<\/p>\n<p><code># Change directory<br \/>\ncd $SWDIR\/util<\/p>\n<p># Set the variable n, which should store the number of iterations,<br \/>\n# either to 4 when condition \"bla_bla\" or else to 20<br \/>\nif bla_bla then<br \/>\n  n=4<br \/>\nelse<br \/>\n  n=20<br \/>\nfi<\/p>\n<p># loop n times and do something in that loop<br \/>\n# (initialize the variable i with 1, then loop as long as i is<br \/>\n# smaller than or equal the variable n. increase i by 1 on<br \/>\n# every looping)<br \/>\nfor (( i=1; i<=$n; i++ ))\ndo\n  .\/swadm add_process 1 BG Y\ndone\n<\/code><\/p>\n<p>Regards,<br \/>\nRajesh Kumar<br \/>\nTwitt me @ <a href=\"http:\/\/twitter.com\/RajeshKumarIn\" target=\"_blank\" rel=\"noopener\">twitter.com\/RajeshKumarIn<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>rajeshkumar created the topic: shell script to run x times Problem: First i need to cd to this directory $SWDIR\/util Second i need to run the following either 4 times or 20 times .\/swadm add_process 1 BG Y how can i put this in a script Regards, Rajesh Kumar Twitt me @ twitter.com\/RajeshKumarIn rajeshkumar replied&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[454],"tags":[138],"class_list":["post-2405","post","type-post","status-publish","format-standard","hentry","category-shell-script","tag-shell"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=2405"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2405\/revisions"}],"predecessor-version":[{"id":2406,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/2405\/revisions\/2406"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=2405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=2405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=2405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}