{"id":5091,"date":"2015-08-11T21:25:17","date_gmt":"2015-08-11T13:25:17","guid":{"rendered":"http:\/\/rmohan.com\/?p=5091"},"modified":"2015-08-13T17:14:54","modified_gmt":"2015-08-13T09:14:54","slug":"shell-scripts-sample","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=5091","title":{"rendered":"shell scripts sample"},"content":{"rendered":"<p>#!\/bin\/bash<br \/>\nfor ((i=1;i&lt;=254;i++))<br \/>\ndo<br \/>\nip=192.168.1.$i<br \/>\nping $ip -c 1 |grep -q &#8216;ttl=&#8217; &amp;&amp; echo &#8220;$ip&#8221; &gt;&gt; alive.txt<br \/>\ndone<\/p>\n<p>#!\/bin\/bash<br \/>\ngroupadd websphere<br \/>\nfor user in app1 app2 app3 app4<br \/>\ndo<br \/>\nuseradd -g websphere -s \/sbin\/nologin -d \/dev\/null $user<br \/>\n(echo $user;echo $user) | smbpasswd -s -a $user<br \/>\ndone<\/p>\n<p>cat access.log |awk &#8216;{print $1}&#8217;|sort |uniq -c |sort -nr |head -10<\/p>\n<p>&nbsp;<\/p>\n<p>#!\/bin\/sh<br \/>\nfor i in 1 3 5 7 10<br \/>\ndo<br \/>\nj=3<br \/>\nwhile (( &#8220;$j&#8221; &gt; &#8220;$i&#8221; ))<br \/>\ndo<br \/>\nif [ &#8220;$i&#8221; -gt 1 ]; then<br \/>\nbreak<br \/>\nfi<br \/>\necho -n &#8221; &#8221;<br \/>\nlet &#8220;j&#8211;&#8221;<br \/>\ndone<\/p>\n<p>k=1<br \/>\nwhile (( &#8220;$k&#8221; &lt;= &#8220;$i&#8221; ))<br \/>\ndo<br \/>\necho -n &#8220;*&#8221;<br \/>\nlet &#8220;k++&#8221;<br \/>\ndone<br \/>\necho &#8221; &#8221;<br \/>\ndone<br \/>\n#!\/bin\/bash<br \/>\nm=1<\/p>\n<p>for ((i=1;i&lt;=100;i++))<br \/>\ndo<br \/>\n#temp1<br \/>\nlet &#8220;temp1=i%7&#8221;<\/p>\n<p>if [ &#8220;$temp1&#8221; -ne 0 ]; then<br \/>\ncontinue<br \/>\nfi<\/p>\n<p>#<br \/>\necho -n &#8220;$i &#8221;<\/p>\n<p>#temp2<br \/>\nlet &#8220;temp2=m%7&#8221;<\/p>\n<p>#7<br \/>\nif [ &#8220;$temp2&#8243; -eq 0 ]; then<br \/>\necho &#8221; &#8221;<br \/>\nfi<\/p>\n<p>let &#8220;m++&#8221;<br \/>\ndone<\/p>\n<p>&nbsp;<br \/>\n#!\/bin\/bash<br \/>\necho &#8220;&#8221;This is a system initialization script, careful&#8221;<br \/>\ninput_fun()<br \/>\n{<br \/>\nOUTPUT_VAR=$1<br \/>\nINPUT_VAR=&#8221;&#8221;<br \/>\nwhile [ -z $INPUT_VAR ];do<br \/>\nread -p &#8220;$OUTPUT_VAR&#8221; INPUT_VAR<br \/>\ndone<br \/>\necho $INPUT_VAR<br \/>\n}<br \/>\ninput_again()<br \/>\n{<br \/>\nMYHOSTNAME=$(input_fun &#8220;please input the hostname:&#8221;)<br \/>\nDOMAINNAME=$(input_fun &#8220;please input the domainname:&#8221;)<br \/>\nCARD_TYPE=$(input_fun &#8220;please input card type(eth0):&#8221;)<br \/>\nIPADDR=$(input_fun &#8220;please input ip address(192.168.100.1):&#8221;)<br \/>\nNETMASK=$(input_fun &#8220;please input netmask(255.255.255.0):&#8221;)<br \/>\nGATEWAY=$(input_fun &#8220;please input gateway(192.168.100.1):&#8221;)<br \/>\nMYDNS1=$(input_fun &#8220;please input DNS1(114.114.114.114):&#8221;)<br \/>\nMYDNS2=$(input_fun &#8220;please input DNS2(8.8.4.4):&#8221;)<br \/>\n}<br \/>\ninput_again<br \/>\nMAC=$(ifconfig $CARD_TYPE | grep &#8220;HWaddr&#8221; | awk -F[&#8221; &#8220;]+ &#8216;{print $5}&#8217;)<\/p>\n<p>#SET COMPUTER NAME<br \/>\ncat &gt;\/etc\/sysconfig\/network &lt;&lt;ENDF<br \/>\nNETWORK=yes<br \/>\nHOSTNAME=$MYHOSTNAME<br \/>\nENDF<\/p>\n<p>cat &gt;\/etc\/sysconfig\/network-scripts\/ifcfg-$CARD_TYPE &lt;&lt;ENDF<br \/>\nDEVICE=$CARD_TYPE<br \/>\nBOOTPROTO=static<br \/>\nHWADDR=$MAC<br \/>\nNM_CONTROLLED=yes<br \/>\nONBOOT=yes<br \/>\nTYPE=Ethernet<br \/>\nIPV6INIT=no<br \/>\nIPADDR=$IPADDR<br \/>\nNETMASK=$NETMASK<br \/>\nGATEWAY=$GATEWAY<br \/>\nENDF<\/p>\n<p>\/etc\/init.d\/network restart<\/p>\n<p>cat &gt;\/etc\/hosts &lt;&lt;ENDF<br \/>\n127.0.0.1 $MYHOSTNAME $MYHOSTNAME.$DOMAINNAME localhost<br \/>\n$IPADDR $MYHOSTNAME $MYHOSTNAME.$DOMAINNAME\u00a0 localhost<br \/>\nENDF<\/p>\n<p>cat &gt;\/etc\/resolv.conf &lt;&lt;ENDF<br \/>\ndomain $DOMAINNAME<br \/>\nsearch $DOMAINNAME<br \/>\nnameserver $MYDNS1<br \/>\nnameserver $MYDNS2<br \/>\nENDF<\/p>\n<p>#Close SELINUX<br \/>\nsed -i &#8216;s\/SELINUX=enforcing\/SELINUX=disabled\/g&#8217; \/etc\/sysconfig\/selinux<br \/>\nsetenforce 0<\/p>\n<p>#Modify number of open files<br \/>\necho &#8220;* soft nofile 66666&#8221; &gt;&gt; \/etc\/security\/limits.conf<br \/>\necho &#8220;* hard nofile 66666&#8221; &gt;&gt; \/etc\/security\/limits.conf<\/p>\n<p>#Optimize the kernel parameters<br \/>\ncat &gt;&gt; \/etc\/sysctl.conf &lt;&lt; ENDF<br \/>\nnet.ipv4.tcp_max_syn_backlog = 65536<br \/>\nnet.core.netdev_max_backlog =\u00a0 32768<br \/>\nnet.core.somaxconn = 32768<br \/>\nnet.core.wmem_default = 8388608<br \/>\nnet.core.rmem_default = 8388608<br \/>\nnet.core.rmem_max = 16777216<br \/>\nnet.core.wmem_max = 16777216<br \/>\nnet.ipv4.tcp_timestamps = 0<br \/>\nnet.ipv4.tcp_synack_retries = 2<br \/>\nnet.ipv4.tcp_syn_retries = 2<br \/>\nnet.ipv4.tcp_tw_recycle = 1<br \/>\n#net.ipv4.tcp_tw_len = 1<br \/>\nnet.ipv4.tcp_tw_reuse = 1<br \/>\nnet.ipv4.tcp_mem = 94500000 915000000 927000000<br \/>\nnet.ipv4.tcp_max_orphans = 3276800<br \/>\nnet.ipv4.ip_local_port_range = 1024\u00a0 65535<br \/>\nENDF<br \/>\nsysctl -p<\/p>\n<p>#Turn off the system without service<br \/>\nfor server in `chkconfig &#8211;list |grep 3:on|awk &#8216;{ print $1}&#8217;`<br \/>\ndo<br \/>\nchkconfig &#8211;level 3 $server off<br \/>\ndone<\/p>\n<p>for server in crond network rsyslog sshd<br \/>\ndo<br \/>\nchkconfig &#8211;level 3 $server on<br \/>\ndone<\/p>\n<p>## Increase user and sudo privilege escalation<br \/>\nuser_add()<br \/>\n{<br \/>\nUSERNAME=$(input_fun &#8220;please input new user name:&#8221;)<br \/>\nuseradd $USERNAME<br \/>\npasswd $USERNAME<br \/>\n}<br \/>\nuser_add<\/p>\n<p>chmod +w \/etc\/sudoers<br \/>\necho &#8220;$USERNAME\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ALL=(ALL)\u00a0\u00a0\u00a0\u00a0 ALL&#8221; &gt;&gt;\/etc\/sudoers<br \/>\nchmod -w \/etc\/sudoers<br \/>\n# Set the time zone synchronization<br \/>\nyum -y install ntpdate<br \/>\n\/usr\/sbin\/ntpdate time.nist.gov<\/p>\n<p>echo &#8220;*\/5 * * * * root \/usr\/sbin\/ntpdate time.nist.gov 1&gt; \/dev\/null 2&gt;&amp;1&#8221; &gt;&gt; \/var\/spool\/cron\/root<\/p>\n<p># Configure SSHD<br \/>\nsed -i &#8216;\/^#Port\/s\/#Port 22\/Port 65535\/g&#8217; \/etc\/ssh\/sshd_config<br \/>\nsed -i &#8216;\/^#UseDNS\/s\/#UseDNS yes\/UseDNS no\/g&#8217; \/etc\/ssh\/sshd_config<br \/>\nsed -i &#8216;s\/#PermitRootLogin yes\/PermitRootLogin no\/g&#8217; \/etc\/ssh\/sshd_config<br \/>\nsed -i &#8216;s\/#PermitEmptyPasswords no\/PermitEmptyPasswords no\/g&#8217; \/etc\/ssh\/sshd_config<br \/>\niptables -A INPUT -p tcp &#8211;dport 65535 -j ACCEPT<br \/>\n\/etc\/init.d\/sshd restart<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#!\/bin\/bash for ((i=1;i&lt;=254;i++)) do ip=192.168.1.$i ping $ip -c 1 |grep -q &#8216;ttl=&#8217; &amp;&amp; echo &#8220;$ip&#8221; &gt;&gt; alive.txt done<\/p>\n<p>#!\/bin\/bash groupadd websphere for user in app1 app2 app3 app4 do useradd -g websphere -s \/sbin\/nologin -d \/dev\/null $user (echo $user;echo $user) | smbpasswd -s -a $user done<\/p>\n<p>cat access.log |awk &#8216;{print $1}&#8217;|sort |uniq -c |sort -nr [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[47],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5091"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5091"}],"version-history":[{"count":4,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5091\/revisions"}],"predecessor-version":[{"id":5093,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/5091\/revisions\/5093"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}