我目前正在開發一個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
提交
取消