我目前正在开发一个python脚本,该脚本生成shell脚本以在Linux服务器上安装代理。python脚本输出.sh文件不断以“语法错误:文件意外结束”结束,但是当我在vi中手动输入确切的输出时,似乎没有问题。我用python编写它的方式是否有任何问题,或者通过python进行编写是否可行?脚本import csvdef menu(): print("type of scripts") print("1. Install + Generation") print("2. Unregister + Reregister") print("3. Unregister + Uninstall")#Converts numeral choice into type for script namingdef choicename(choice): choice = int(choice) if choice==1: return "install" elif choice == 2 : return "rereg" else: return "uninstall"#Generates the install agent scripts def installScript(agentname,agentfile,mgrfile,prigw,secgw,ostype): #Generates the script for Linux agents (.sh) if ostype=="Linux": agentpath = 'agent="/opt/test/ragent/bin/racli"' installerpath = '\ninstaller="/opt/test/installer/bin/racli"' checkAgent = '\nif [ ! -e "$agent" ]; then' +"\n" + "./" + agentfile + " -n -d /opt/test" + '\nelse\necho "Agent is already installed"\nfi' checkInstaller = '\nif [ ! -e "$installer" ]; then' + "\n" +"./" + mgrfile + " -n -d /opt/test"+ '\nelse\necho "Manager is already installed"\nfi' regAgent = "\n/opt/test/ragent/bin/cli registration advanced-register registration-type=Primary ragent-name="+ agentname+ " gw-ip="+ prigw+ " gw-port=443 manual-settings-activation=Automatic monitor-networkchannels=Both password=$1" if secgw!="": regAgent+="\n/opt/test/ragent/bin/cli registration advanced-register registration-type=Secondary ragent-name="+ agentname+ " gw-ip="+ secgw+ " gw-port=443 manual-settings-activation=Automatic monitor-networkchannels=Both password=$1" startAgent="\n/opt/test/ragent/bin/rainit start"
添加回答
举报
0/150
提交
取消