linux 下面程序自动安装脚本
来源:互联网 发布:化学方程式书写软件 编辑:程序博客网 时间:2024/06/09 17:33
在此脚本中,主要用的是bash shell,需求为利用telnet或ssh把脚本写到服务器里面,让服务器执行脚本,从ftp服务器里面下载最新版本的程序,并解压执行。脚本内容如下:
#!/bin/bash# install agent scriptftpIp="10.22.2.21"ftpPort=2122agentIp="10.22.2.22"ftpUserName="test"ftpUserPwd="123456"ftpAgentPath="/main/v1.0"ftpAgentFileName="agent.zip"ftpJrePath="/java/linux/x86"ftpJreName="jre.zip"ftpErrorPath="/error"agentSaveDir="/home/fan/agent"agentContextName="hyperagent"installAgentScriptPathName="agentscript"installAgentScriptFileName="installAgent.sh"startAgentScriptName="startup.sh"uninstallAgentScriptName="shutdown.sh"tempPortFileName="tempPortFileName.txt"agentPort=4850# $1 native absolutely file path# $2 remote path # $3 new file namefunction ftpUpload(){ftp -n<<!open $ftpIp $ftpPortuser $ftpUserName $ftpUserPwdbinarypromptcd $2put $1 $3closebye!}#ftpUpload "/home/boco/jre.zip" "/main" "jre2.zip"# $1 native absolutely file path# $2 remote path# $3 remote file namefunction ftpDownload(){ftp -n<<!open $ftpIp $ftpPortuser $ftpUserName $ftpUserPwdbinarylcd $1cd $2promptmget $3closebye!}#ftpDownload "/home/boco" "/main/v1.0" "hyperagent.zip"agentScriptFullDir="$agentSaveDir/$installAgentScriptPathName"# $1 is msgfunction uploadAgentLog(){tempLogFullName="$agentScriptFullDir/$agentIp.log"echo $1 > $tempLogFullNameftpUpload $tempLogFullName $ftpErrorPath "$agentIp.log"}function uninstallAgent(){echo "begin unistall agent"echo "begin check port $agentPort status"aport=`netstat -lntp | grep ":$agentPort "`if [ -z "$aport" ]then echo "port $agentPort free"else echo "port $agentPort busy"uninstallScriptFullPath="$agentSaveDir/$agentContextName/bin" echo "begin invoke $uninstallScriptFullPath/$uninstallAgentScriptName to stop agent"if [ -e "$uninstallScriptFullPath/$uninstallAgentScriptName" ]thencd $uninstallScriptFullPathsh $uninstallAgentScriptNamesleep 3 echo "end invoke $uninstallScriptFullPath/$uninstallAgentScriptName"else echo "$uninstallScriptFullPath/$uninstallAgentScriptName not exist"fifiecho "begin delete $agentSaveDir/$agentContextName"rm -rf "$agentSaveDir/$agentContextName"echo "end delete $agentSaveDir/$agentContextName"# delete temp zipfilerm -rf "$agentScriptFullDir/$ftpAgentFileName" rm -rf "$agentScriptFullDir/$ftpJreName" echo "end uninstall agent"}function installAgent2(){#echo $agentScriptFullDirecho "begin download main agent"ftpDownload $agentScriptFullDir $ftpAgentPath $ftpAgentFileNameecho "end download main agent"echo "begin download jre"ftpDownload $agentScriptFullDir $ftpJrePath $ftpJreNameecho "end download jre"echo "begin unzip main agent"unzip -o -d $agentSaveDir "$agentScriptFullDir/$ftpAgentFileName" >>/dev/nullecho "end unzip main agent"echo "begin unzip jre"unzip -o -d "$agentSaveDir/$agentContextName" "$agentScriptFullDir/$ftpJreName" >>/dev/nullecho "end unzip jre"# grant user x priviledge of jre and binecho "begin grant current user x priviledge of agent"chmod -R u=rwx "$agentSaveDir/$agentContextName"echo "end grant current user x priviledge of agent"# start agentecho "start agent"cd "$agentSaveDir/$agentContextName/bin/"sh $startAgentScriptName#sh "$agentSaveDir/$agentContextName/$startAgentScriptName"echo "start agent end"sleep 3echo "the third time to check port $agentPort status"aport=`netstat -lntp | grep ":$agentPort "`if [ -z "$aport" ]then echo "agent installed but start error on port $agentPort"uploadAgentLog "agent installed but start error on port $agentPort"else echo "agent start success on port $agentPort"fi#unzip #unzip -o -d /home/boco/agent/agentscript/ hyperagent.zip#echo "end"}function installAgent(){uninstallAgentecho "again check port $agentPort status"aport=`netstat -lntp | grep ":$agentPort "`if [ -z "$aport" ]then echo "port free"installAgent2else echo "port $agentPort busy and cannot be removed,stop install agent"uploadAgentLog "port $agentPort busy and cannot be removed,stop install agent"fiecho "install complete!"}installAgent
- linux 下面程序自动安装脚本
- linux 脚本实现程序自动安装
- linux自动安装脚本
- linux中的自动安装脚本
- linux自动安装系统脚本
- Linux中的自动安装脚本
- Linux中的自动安装脚本
- Linux中的自动安装脚本
- Linux-自动安装的脚本
- Linux开机自动运行脚本程序
- Linux Shell 脚本 自动备份 程序 源码
- Linux下自动安装Proftpd服务脚本
- Linux自动安装JDK的shell脚本
- Linux系统tomcat自动安装shell脚本
- 自动安装linux系统的脚本
- 利用脚本自动安装Linux系统
- linux中的自动安装虚拟机脚本
- Linux Unit14--虚拟机的自动安装脚本
- 解决跨域问题
- ubuntu ntp时间同步服务器搭建与使用
- XHTML与HTML的一些特点与区别
- WdatePicker日历控件使用方法
- java 枚举类型enum 的使用
- linux 下面程序自动安装脚本
- C#-单词首字母大写
- Hadoop MapReduce之任务启动(一)
- json基础
- android RatingBar自定义图片
- STL中的sort()与qsort()
- 非oracle用户执行sqlplus
- 1795[Table Tennis]
- android 随手记 --byte String inputstream 之间的转换