设为首页 收藏本站
查看: 1140|回复: 0

shell3-pl

[复制链接]

尚未签到

发表于 2018-8-23 08:40:35 | 显示全部楼层 |阅读模式
  ontinue
  break
  # vim s25.sh
  #!/bin/bash
  for  i in `seq 1 10`
  do
  if [ $i -eq 5 ]
  then
  continue
  fi
  echo $i
  done
  [test]#chmod +x s25.sh
  [test]#./s25.sh
  1
  2
  3
  4
  6
  7
  8
  9
  10
  [test]#vim s25.sh
  #!/bin/bash
  for  i in `seq 1 10`
  do
  if [ $i -eq 5 ]
  then
  break
  fi
  echo $i
  done
  You have new mail in /var/spool/mail/root
  [test]#chmod +x s26.sh
  [test]#./s26.sh
  1
  2
  3
  4
  练习:输入用户名和密码 ,如果是root和redhat,输出“欢迎光临“,如果不正确,输出“不正确,请重新输入用户名和密码“。
  # vim s27.sh
  #!/bin/bash
  while :
  do
  read -p "请输入用户名:" username
  read -s -p "请输入密码:" password
  if [ $username -eq "root" -a $password -eq "redhat" ]
  then
  echo "欢迎光临"
  break
  else
  echo "不正确,请重新输入用户名和密码"
  fi
  done
  ~
  练习: 限制尝试次数为5次,5次以后禁止使用。
  # vim s28.sh
  #!/bin/bash
  i=1
  while [ $i -le 5 ]
  do
  read -p "请输入用户名:" username
  read -s -p "请输入密码:" password
  echo
  if [ $username == "root" -a $password == "redhat" ]
  then
  echo "欢迎光临"
  break
  elif [ $i -eq 5  ]
  then
  echo "你无权使用本程序"
  break
  else
  echo "不正确,你还有$[5-$i]次机会,请重新输>入用户名和密码"
  fi
  i=$[$i+1]
  done
  # chmod +x s28.sh
  # ./s28.sh
  -------------------------------
  > <  |  结合done  用
  1) >
  # vim s29.sh
  #!/bin/bash
  for i in `seq 1 10`
  do
  echo $i
  done>/test/1.txt
  # chmod +x s29.sh
  [test]#./s29.sh
  [test]#cat /test/1.txt
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
  --------------------
  2)  < while循环
  批量添加用户
  [test]#vim  user_list
  utom     utomg    2000   /utom    /bin/bash   utomutom
  jarry    jarryg   2001   /jarry   /bin/zsh    jarryjarry
  larry    larryg   2002   /larry   /bin/tcsh   larrylarry
  #!/bin/bash
  #add user scripts
  while read line
  do
  uname=$(echo $line|awk '{print $1}')
  gname=$(echo $line|awk '{print $2}')
  uid=$(echo $line|awk '{print $3}')
  home=$(echo $line|awk '{print $4}')
  shell=$(echo $line|awk '{print $5}')
  passwd=$(echo $line|awk '{print $6}')
  grep "^\" /etc/group &>/dev/null
  if [ $? -ne 0 ]
  then
  groupadd $gname
  fi
  id $uname &>/dev/null
  if [ $? -ne 0 ]
  then
  useradd -g $gname -u $uid -d $home -s $shell $uname
  echo $passwd |passwd --stdin $uname
  fi
  done/test/ip.txt
  while read line
  do
  ip=$(echo $line|awk '{print $2}')
  iptables -I INPUT -s $ip -p tcp --dport 22 -j DROP
  done/dev/null
  }
  wd='192.168.3.'
  for i in `seq 1 254`
  do
  echo $wd$i
  done>/tmp/ip1.txt
  while read ip
  do
  testip $ip
  if [ $? -eq 0 ]
  then
  echo $ip >> /tmp/ip.txt
  fi
  done /root/.ssh/known_hosts
  # vim auto.exp
  #!/usr/bin/expect
  set timeout 60
  spawn ssh 192.168.3.2
  expect "continue connecting"
  send "yes\r"
  expect "password:"
  send "redhat1\r"
  interact
  # chmod +x auto.exp
  # ./auto.exp
  --------------------------
  脚本加密
  # tar zxvf shc-3.8.7.tgz -C /usr/local/src
  shc-3.8.7/CHANGES
  shc-3.8.7/Copying
  shc-3.8.7/Makefile
  shc-3.8.7/match
  shc-3.8.7/pru.sh
  shc-3.8.7/shc-3.8.7.c
  shc-3.8.7/shc.1
  shc-3.8.7/shc.README
  shc-3.8.7/shc.c
  shc-3.8.7/shc.html
  shc-3.8.7/test.bash
  shc-3.8.7/test.csh
  shc-3.8.7/test.ksh
  # cd /usr/local/src
  # cd shc-3.8.7/
  # make
  # make test
  # make strings
  # make expiration
  # ./shc -e 13/07/2013 -m "please connect larry@gmail.com" -f /test/aaa.sh
  ---------------------------------
  脚本调试
  1) 设置断点  echo
  2)sh -x file.sh


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-555344-1-1.html 上篇帖子: nmap配合shell使用 下篇帖子: shell中echo的用法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表