{"id":114,"date":"2009-01-22T14:32:02","date_gmt":"2009-01-22T06:32:02","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/?p=114"},"modified":"2012-02-11T18:47:40","modified_gmt":"2012-02-11T10:47:40","slug":"how-to-increment-a-bashkorn-variable","status":"publish","type":"post","link":"http:\/\/www.sysadmindayph.com\/blog\/how-to-increment-a-bashkorn-variable\/","title":{"rendered":"How To Increment a (Bash\/Korn) Variable"},"content":{"rendered":"<p>Ever wonder how to increment a number inside a variable in a bash or korn shell? If you&#8217;re the geeky type of guy, I&#8217;m sure you know how..<br \/>\n<script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"ca-pub-8839128323193448\";\n\/* sysadmin-bigsquare *\/\ngoogle_ad_slot = \"0154488356\";\ngoogle_ad_width = 336;\ngoogle_ad_height = 280;\n\/\/-->\n<\/script><br \/>\n<script type=\"text\/javascript\"\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><\/p>\n<p>Well, this quick post is sort of like a note to self.. I jsut want to have it handy in case I need it again.. and for sure, I will need it again..<\/p>\n<p>Anyway, hours are spent searching for the correct format or syntax on the variable, so here it is:<\/p>\n<p>while [[ $NUMBER != $CNTR1 ]]<br \/>\ndo<br \/>\n# Separation.. one file each line<br \/>\n#<br \/>\nhead -$CNTR1 list | tail -1 &gt; .\/processing\/$FILENAME.$CNTR1<br \/>\n<script type=\"text\/javascript\"><!--\ngoogle_ad_client = \"ca-pub-8839128323193448\";\n\/* sysadmin-bigsquare *\/\ngoogle_ad_slot = \"0154488356\";\ngoogle_ad_width = 336;\ngoogle_ad_height = 280;\n\/\/-->\n<\/script><br \/>\n<script type=\"text\/javascript\"\nsrc=\"http:\/\/pagead2.googlesyndication.com\/pagead\/show_ads.js\">\n<\/script><br \/>\n# moved (or copy) &#8216;feedme&#8217; as &#8216;list&#8217;<br \/>\ncp .\/processing\/$FILENAME.$CNTR1 .\/processing\/list<\/p>\n<p>## ADD the &#8216;t&#8217; and &#8216;x&#8217; logic here<br \/>\n##<br \/>\nawk &#8216;{print $1}&#8217; .\/processing\/list &gt; .\/processing\/cutfile<br \/>\nACCT=`cut -c1 .\/processing\/cutfile`<br \/>\nif [ $ACCT !=\u00a0 1 ]<br \/>\nthen<br \/>\nPREFIX=&#8217;t&#8217;<br \/>\nelse<br \/>\nPREFIX=&#8217;x&#8217;<\/p>\n<p>fi<br \/>\nUID=`awk &#8216;{print $1}&#8217; .\/processing\/list`<br \/>\necho &#8220;UID is $PREFIX$UID&#8221;<br \/>\nNAME=`awk &#8216;{print $2}&#8217; .\/processing\/list`<br \/>\ncat .\/processing\/list<br \/>\necho $PREFIX<br \/>\n## END OF T and X Logic<\/p>\n<p>## CHECK if user exists or not<br \/>\n## If New User, Create it<br \/>\n##<br \/>\ncat \/etc\/passwd | grep $UID<br \/>\nreturn=$?<br \/>\nif [ $return = 0 ]<br \/>\nthen<br \/>\necho &#8220;User account already exist&#8221;<br \/>\nexit<br \/>\nelse<br \/>\nuseradd -d $HOMEDIR$PREFIX$UID -g $GROUPMEM -G $SUPGROUP -s $USERSHELL -c &#8220;$COMMENTS$NAME `date &#8216;+%d%b%y&#8217;`&#8221; -m $PREFIX$UID<br \/>\n#echo $HOMEDIR$PREFIX$UID $GROUPMEM -G $SUPGROUP -s $USERSHELL -c &#8220;$COMMENTS$NAME `date &#8216;+%d%b%y&#8217;`&#8221;\u00a0\u00a0 -m\u00a0 $PREFIX$UID<br \/>\necho &#8220;$PREFIX$UID:telus2009&#8221; | chpasswd<br \/>\n#echo &#8220;$PREFIX$UID:telus2009&#8221;<br \/>\necho &#8220;Let&#8217;s continue&#8221;<br \/>\nfi<br \/>\n<strong> <span style=\"color: #ff0000;\"> CNTR1=$(($CNTR1+1))<\/span><\/strong><br \/>\nsleep 1<br \/>\ndone<\/p>\n<p>It&#8217;s the bold and red text&#8230; Hope it helps someone.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever wonder how to increment a number inside a variable in a bash or korn shell? If you&#8217;re the geeky type of guy, I&#8217;m sure you know how.. Well, this quick post is sort of &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[121,122,376],"class_list":["post-114","post","type-post","status-publish","format-standard","hentry","category-scripting","tag-bash","tag-korn","tag-scripting"],"_links":{"self":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=114"}],"version-history":[{"count":1,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":306,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/114\/revisions\/306"}],"wp:attachment":[{"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}