为什么该bash脚本不能在Ubuntu上执行,但是可以在在线环境上执行呢?

艾略特实验室有限责任公司

我不知道为什么这不能在Ubuntu上正常工作。当我在CompileOnline上执行脚本时,它的效果很好但是当我在本地服务器上运行它时,它没有显示主菜单,而是从顶部开始读取命令列表。

该脚本应该是菜单系统。根据用户选择的内容,将发生什么动作。也有注释,因此您可以查看每个代码部分的功能。

    #!/bin/su

    # Ititialization

    function installsamba {
      sudo apt-get update
      sudo apt-get -y dist-upgrade
      sudo apt-get -y install git build-essential libacl1-dev libattr1-dev libblkid-dev libgnutls-dev libreadline-dev python-dev python-dnspython gdb pkg-config libpopt-dev libldap2-dev dnsutils libbsd-dev attr krb5-user docbook-xsl libcups2-dev acl
      git clone git://git.samba.org/samba.git samba-master
      cd samba-master
      ./configure
      sudo make
      sudo make install
      sudo rm -f -R samba-master
      sed -i "5i PATH=$PATH:/usr/local/samba/bin" ~/.bashrc
      sed -i "5i PATH=$PATH:/usr/local/samba/sbin" ~/.bashrc
      sudo sed -i "5i PATH=$PATH:/usr/local/samba/bin" /root/.bashrc
      sudo sed -i "5i PATH=$PATH:/usr/local/samba/sbin" /root/.bashrc
      mainmenu
      }

    # This installs all of the necessary components for building samba then downloads samba from git.
    # After that it then compiles and installs samba and returns to the main menu.

    function installvsftpd {
      sudo apt-get update
      sudo apt-get -y dist-upgrade
      sudo apt-get -y install vsftpd
      mainmenu
      }

    # This installs VSFTPd and return to the main menu.


    function installwebmin {
      wget http://www.webmin.com/download/deb/webmin-current.deb
      sudo apt-get update
      sudo apt-get -y dist-upgrade
      sudo dpkg -i webmin-current.deb
      sudo apt-get -y install -f
      rm webmin-current.deb
      mainmenu
      }

    # This installs the current version of WebMin and then returns to the main menu.

    function updatesystem {
      sudo apt-get update
      sudo apt-get -y dist-upgrade
      echo "Update Complete!"
      echo "It may be wise to restart your computer..."
      read -N 1
      clear
      mainmenu
      }

    # This install the latest updates for the system and then returns to the main menu.


    function configuresambaforactivedirectory {
      sudo sed -i.original -r '/[ \t]\/[ \t]/{s/(ext4[\t ]*)([^\t ]*)/\1\2,user_xattr,acl,barrier=1/}' /etc/fstab
      mount -a
      sudo /usr/local/samba/bin/samba-tool domain provision
      sudo mv /etc/krb5.conf /etc/krb5.conf.bak
      sudo cp /usr/local/samba/private/krb5.conf /etc/krb5.conf
      sudo sed -i "13i sudo /usr/local/samba/sbin/samba" /etc/rc.local
      sudo /usr/local/samba/sbin/samba
      domaincontrolleryorn
      }

    # This function runs all of the necessary actions to make samba a domain controller.


    function domaincontrolleryorn {
      echo "did you set this instalation as a primary domain controller?"
      echo ""
      echo "If you select yes then it will upgrade the forrest and domain to"
      echo "Server 2008 R2 levels. This may break compatibility with earlier"
      echo "versions of Windows Server. You can alwayse manually change the levels"
      echo "if you wish... Press wisely!"
      echo ""
      echo "Y or N:"
      read -N 1 -p "Y or N:" domaincontrolleryesorno
      if [ $domaincontrolleryesorno = "Y" ]; then
       upgradeforrestanddomain
       elif [ "$$domaincontrolleryesorno" = "N" ]; then
                clear
                echo "Samba configuration complete!"
                echo "Press any key to continue..."
                read -N 1
                mainmenu
        elif [ "$$domaincontrolleryesorno" = "n" ]; then
                clear
                echo "Samba configuration complete!"
                echo "Press any key to continue..."
                read -N 1
                mainmenu
        elif [ "$$domaincontrolleryesorno" = "y" ]; then
                upgradeforrestanddomain
        else
          echo "Please press either Y or N!!!"
          echo ""
          echo "Press any key to continue..."
          read -N 1
          clear
          domaincontrolleryorn
        fi
      }

# This asks the user if he or she would like to upgrade the domain and forrest level.
# If yes then it roputs the user to the code below. If not then the user is taken to the main menu.

    function upgradeforrestanddomain  {
      sudo /usr/local/samba/bin/samba-tool domain level raise --domain-level=2008_R2
      sudo /usr/local/samba/bin/samba-tool domain level raise --forest-level=2008_R2
      sudo /usr/local/samba/bin/samba-tool domain passwordsettings set --complexity=off
      echo "Domain Controller setup has completed!"
      echo ""
      echo "Press any key to return to the main menu..."
      read -N 1
      clear
      mainmenu
      }


    # This function upgrade the Domain and Forrest level to (Server) 2008_R2.
    # Acceptable levels are 2008 and 2008 R2. The default is 2003.


    function quitprogram {
      clear
      echo "Sorry to see you go... :("
      exit
      }

    # This is a simple good by program closer.
    # Oh, did I mention that it stops the program?


    function mainmenu {
      echo "Press 1 to update your system"
      echo "Press 2 to install samba"
      echo "Press 3 to install vsFTPd"
      echo "Press 4 to install the current version of Webmin"
      echo "Press 5 to configure samba for Active Directory"
      echo "Press x to exit the script"
      read -N 1 -p "Input Selection:" mainmenuinput
      if [ "$mainmenuinput" = "1" ]; then
                updatesystem
            elif [ "$mainmenuinput" = "2" ]; then
                installsamba
            elif [ "$mainmenuinput" = "3" ]; then
                installvsftpd
            elif [ "$mainmenuinput" = "4" ]; then
                installwebmin
            elif [ "$mainmenuinput" = "5" ]; then
                configuresambaforactivedirectory
            elif [ "$mainmenuinput" = "x" ];then
                quitprogram
            elif [ "$mainmenuinput" = "X" ];then
                quitprogram
            else
                echo "You have entered an invallid selection!"
                echo "Please try again!"
                echo ""
                echo "Press any key to continue..."
                read -N 1
                clear
                mainmenu
            fi
    }

    mainmenu

    # This executes the main menu function.
    # Let the fun begin!!!! WOOT WOOT!!!!

有人可以帮我吗?

艾略特实验室有限责任公司

事实证明,我为Ubuntu创建的函数不正确。我还更改了shebang只是为了确保系统能够正确解释它,但我认为它没有太大的不同:-P这是起作用的代码:

#!/bin/bash

# Ititialization

installsamba () {
  sudo apt-get update
  sudo apt-get -y dist-upgrade
  sudo apt-get -y install git build-essential libacl1-dev libattr1-dev libblkid-dev libgnutls-dev libreadline-dev python-dev python-dnspython gdb pkg-config libpopt-dev libldap2-dev dnsutils libbsd-dev attr krb5-user docbook-xsl libcups2-dev acl
  git clone git://git.samba.org/samba.git samba-master
  cd samba-master
  ./configure
  sudo make
  sudo make install
  sudo rm -f -R samba-master
  sed -i "5i PATH=$PATH:/usr/local/samba/bin" ~/.bashrc
  sed -i "5i PATH=$PATH:/usr/local/samba/sbin" ~/.bashrc
  sudo sed -i "5i PATH=$PATH:/usr/local/samba/bin" /root/.bashrc
  sudo sed -i "5i PATH=$PATH:/usr/local/samba/sbin" /root/.bashrc
  mainmenu
  }

# This installs all of the necessary components for building samba then downloads samba from git.
# After that it then compiles and installs samba and returns to the main menu.

installvsftpd () {
  sudo apt-get update
  sudo apt-get -y dist-upgrade
  sudo apt-get -y install vsftpd
  mainmenu
  }

# This installs VSFTPd and return to the main menu.


installwebmin () {
  wget http://www.webmin.com/download/deb/webmin-current.deb
  sudo apt-get update
  sudo apt-get -y dist-upgrade
  sudo dpkg -i webmin-current.deb
  sudo apt-get -y install -f
  rm webmin-current.deb
  mainmenu
  }

# This installs the current version of WebMin and then returns to the main menu.

updatesystem () {
  sudo apt-get update
  sudo apt-get -y dist-upgrade
  echo "Update Complete!"
  echo "It may be wise to restart your computer..."
  read -n 1
  clear
  mainmenu
  }

# This install the latest updates for the system and then returns to the main menu.


configuresambaforactivedirectory () {
  sudo sed -i.original -r '/[ \t]\/[ \t]/{s/(ext4[\t ]*)([^\t ]*)/\1\2,user_xattr,acl,barrier=1/}' /etc/fstab
  mount -a
  sudo /usr/local/samba/bin/samba-tool domain provision
  sudo mv /etc/krb5.conf /etc/krb5.conf.bak
  sudo cp /usr/local/samba/private/krb5.conf /etc/krb5.conf
  sudo sed -i "13i sudo /usr/local/samba/sbin/samba" /etc/rc.local
  sudo /usr/local/samba/sbin/samba
  domaincontrolleryorn
  }

# This function runs all of the necessary actions to make samba a domain controller.


domaincontrolleryorn () {
  echo "did you set this instalation as a primary domain controller?"
  echo ""
  echo "If you select yes then it will upgrade the forrest and domain to"
  echo "Server 2008 R2 levels. This may break compatibility with earlier"
  echo "versions of Windows Server. You can alwayse manually change the levels"
  echo "if you wish... Press wisely!"
  echo ""
  echo "Y or N:"
  read -n 1 -p "Y or N:" "omaincontrolleryesorno"
  if [ $domaincontrolleryesorno = "Y" ]; then
   upgradeforrestanddomain
   elif [ "$$domaincontrolleryesorno" = "N" ]; then
            clear
            echo "Samba configuration complete!"
            echo "Press any key to continue..."
            read -n 1
            mainmenu
    elif [ "$$domaincontrolleryesorno" = "n" ]; then
            clear
            echo "Samba configuration complete!"
            echo "Press any key to continue..."
            read -n 1
            mainmenu
    elif [ "$$domaincontrolleryesorno" = "y" ]; then
            upgradeforrestanddomain
    else
      echo "Please press either Y or N!!!"
      echo ""
      echo "Press any key to continue..."
      read -n 1
      clear
      domaincontrolleryorn
    fi
  }

# This asks the user if he or she would like to upgrade the domain and forrest level.
# If yes then it roputs the user to the code below. If not then the user is taken to the main menu.

upgradeforrestanddomain () {
  sudo /usr/local/samba/bin/samba-tool domain level raise --domain-level=2008_R2
  sudo /usr/local/samba/bin/samba-tool domain level raise --forest-level=2008_R2
  sudo /usr/local/samba/bin/samba-tool domain passwordsettings set --complexity=off
  echo "Domain Controller setup has completed!"
  echo ""
  echo "Press any key to return to the main menu..."
  read -n 1
  clear
  mainmenu
  }


# This function upgrade the Domain and Forrest level to (Server) 2008_R2.
# Acceptable levels are 2008 and 2008 R2. The default is 2003.


quitprogram () {
  clear
  echo "Sorry to see you go... :("
  exit
  }

# This is a simple good by program closer.
# Oh, did I mention that it stops the program?


mainmenu () {
  echo "Press 1 to update your system"
  echo "Press 2 to install samba"
  echo "Press 3 to install vsFTPd"
  echo "Press 4 to install the current version of Webmin"
  echo "Press 5 to configure samba for Active Directory"
  echo "Press x to exit the script"
  read -n 1 -p "Input Selection:" "mainmenuinput"
  if [ "$mainmenuinput" = "1" ]; then
            clear
            updatesystem
        elif [ "$mainmenuinput" = "2" ]; then
            clear
            installsamba
        elif [ "$mainmenuinput" = "3" ]; then
            clear
            installvsftpd
        elif [ "$mainmenuinput" = "4" ]; then
            clear
            installwebmin
        elif [ "$mainmenuinput" = "5" ]; then
            clear
            configuresambaforactivedirectory
        elif [ "$mainmenuinput" = "x" ];then
            clear
            quitprogram
        elif [ "$mainmenuinput" = "X" ];then
            clear
            quitprogram
        else
            echo "You have entered an invallid selection!"
            echo "Please try again!"
            echo ""
            echo "Press any key to continue..."
            read -n 1
            clear
            mainmenu
        fi
}

# This builds the main menu and routs the user to the function selected.

mainmenu

# This executes the main menu function.
# Let the fun begin!!!! WOOT WOOT!!!!

您可以在github上找到此脚本:https : //github.com/elliot-labs/Ubuntu-Server-Setup-Automation以后我将对其进行更新以添加更多功能。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

为什么在CentOS上运行的awk脚本不能在Ubuntu上运行?

来自分类Dev

为什么在CentOS上运行的awk脚本不能在Ubuntu上运行?

来自分类Dev

为什么我不能在硬盘上安装Windows,但是Ubuntu可以呢?

来自分类Dev

Google登录名可以在localhost上使用,但不能在在线域上使用

来自分类Dev

为什么此脚本不能与nohup一起使用,但是不能,不能呢?

来自分类Dev

为什么此脚本不能与nohup一起使用,但是不能,不能呢?

来自分类Dev

为什么工作脚本不能作为cron作业执行?

来自分类Dev

为什么执行bash脚本时不能加载模块,而只能在采购时加载模块?

来自分类Dev

为什么我不能在PHP FFI中的结构上使用字,字节?但是char,int和short作品呢?

来自分类Dev

为什么我不能在PHP FFI中的结构上使用字,字节?但是char,int和short作品呢?

来自分类Dev

为什么这个C ++程序可以在MacOS上编译而不能在Ubuntu上编译?

来自分类Dev

为什么我的python的socket.shutdown可以在Windows上运行而不能在Ubuntu上运行?

来自分类Dev

为什么curl不能在循环内扩展变量,但是echo可以呢?

来自分类Dev

为什么这种闭包不能在int范围的每个元素上执行?

来自分类Dev

为什么该命令不能在Windows XP上运行?

来自分类Dev

为什么我不能在Linux上执行Android x86可执行文件

来自分类Dev

为什么我的Ruby脚本不执行?

来自分类Dev

为什么我的shell变量串联不能在ubuntu bash上运行?

来自分类Dev

为什么某些东西可以在节点中执行,而不能在REPL中执行?

来自分类Dev

为什么我不能在Ubuntu 12.04上编译GLIBC?

来自分类Dev

为什么我不能在Ubuntu 12.04上编译GLIBC?

来自分类Dev

为什么我不能在ubuntu 18.04上安装mediatomb?

来自分类Dev

为什么亚行不能在Ubuntu 11.10上运行?

来自分类Dev

当我可以在EXE上执行时,为什么不能编译DLL

来自分类Dev

为什么我的shell脚本不能按顺序执行?(可能是imagemagick吗?)

来自分类Dev

为什么此正则表达式可以在Ubuntu上通过但不能在Mac OS X上通过

来自分类Dev

XORing可执行文件时,为什么我的XOR程序不能在Windows上运行

来自分类Dev

为什么我可以在 Git Bash 应用程序中使用我的 RSA 密钥,而不能在我的 Windows 机器上与 Ubuntu WSL 一起使用?

来自分类Dev

为什么jQuery脚本可以在本地主机上运行但不能在Web服务器上运行?

Related 相关文章

  1. 1

    为什么在CentOS上运行的awk脚本不能在Ubuntu上运行?

  2. 2

    为什么在CentOS上运行的awk脚本不能在Ubuntu上运行?

  3. 3

    为什么我不能在硬盘上安装Windows,但是Ubuntu可以呢?

  4. 4

    Google登录名可以在localhost上使用,但不能在在线域上使用

  5. 5

    为什么此脚本不能与nohup一起使用,但是不能,不能呢?

  6. 6

    为什么此脚本不能与nohup一起使用,但是不能,不能呢?

  7. 7

    为什么工作脚本不能作为cron作业执行?

  8. 8

    为什么执行bash脚本时不能加载模块,而只能在采购时加载模块?

  9. 9

    为什么我不能在PHP FFI中的结构上使用字,字节?但是char,int和short作品呢?

  10. 10

    为什么我不能在PHP FFI中的结构上使用字,字节?但是char,int和short作品呢?

  11. 11

    为什么这个C ++程序可以在MacOS上编译而不能在Ubuntu上编译?

  12. 12

    为什么我的python的socket.shutdown可以在Windows上运行而不能在Ubuntu上运行?

  13. 13

    为什么curl不能在循环内扩展变量,但是echo可以呢?

  14. 14

    为什么这种闭包不能在int范围的每个元素上执行?

  15. 15

    为什么该命令不能在Windows XP上运行?

  16. 16

    为什么我不能在Linux上执行Android x86可执行文件

  17. 17

    为什么我的Ruby脚本不执行?

  18. 18

    为什么我的shell变量串联不能在ubuntu bash上运行?

  19. 19

    为什么某些东西可以在节点中执行,而不能在REPL中执行?

  20. 20

    为什么我不能在Ubuntu 12.04上编译GLIBC?

  21. 21

    为什么我不能在Ubuntu 12.04上编译GLIBC?

  22. 22

    为什么我不能在ubuntu 18.04上安装mediatomb?

  23. 23

    为什么亚行不能在Ubuntu 11.10上运行?

  24. 24

    当我可以在EXE上执行时,为什么不能编译DLL

  25. 25

    为什么我的shell脚本不能按顺序执行?(可能是imagemagick吗?)

  26. 26

    为什么此正则表达式可以在Ubuntu上通过但不能在Mac OS X上通过

  27. 27

    XORing可执行文件时,为什么我的XOR程序不能在Windows上运行

  28. 28

    为什么我可以在 Git Bash 应用程序中使用我的 RSA 密钥,而不能在我的 Windows 机器上与 Ubuntu WSL 一起使用?

  29. 29

    为什么jQuery脚本可以在本地主机上运行但不能在Web服务器上运行?

热门标签

归档