linux本地agent执行脚本_linux OCSNG agent脚本自动安装说明

ocs agent linux客户端一键自动化安装脚本,应用于Debian类和redhat类linux系统。

所需软件,2个文件:

cacert.pem

这个文件是CA的根证书,可以看看【架设CA服务器实现https通信,web服务器使用CA自签证书与https通信http://990487026.blog.51cto.com/10133282/1686127】

基于https通信,可以使用OCS的IPdiscover功能。

-rw-r--r--.  1 root root  59M 8月  20 16:57 linux-ocs-agent.tar.gz

Ready Go!

===================================================

tar xf OCS_Agent0812.1028.tar.gz

2,【执行安装】【没有root权限会报错,提示用 sudo su】

root@debian:/home# cd linux/

root@debian:/home/linux/# ./install.sh

3,【输入机器的资产编号,不要输错!】

Vobile: Enter TAG  on this machine :

【显示Successful! 说明客户端安装成功,下面会显示这个机器的当前分钟是多少】

Successful!

57

#!/bin/bash

# cacert.pem

# deb.txt

# yum packages

# Ocsinventory-agent

# fix cron time

# fix sync time

# if test ok,modify debug=0

# 2015.08.14 fix redhat linux yum depend problems

# 2015.08.14 fix seting cron time

# 2015.08.17 grep Successful or break

#

export PATH=$PATH:.

clear

setterm -blank 0

root_id=`id -u`

if [ $root_id -ne 0 ] ; then

{

clear

echo -e "\033[40;37mWarning: you are not root user ! \n\n[Please use Command line ]$ sudo su \n\n \033[0m"

exit 10

}

fi

#judenment operation OS ************************************

rm -rf /etc/ocsinventory*     #rm old agent conf

if [ -f /etc/redhat-release ]

then

OS=1

elif [ -f /etc/debian_version ]

then

OS=2

else

clear

echo "No support Operating system !"

fi

# Debian ********************************

if [ $OS -eq 2 ] ;then

echo "Debian Linux"

sleep 1

cp /etc/apt/sources.list /etc/apt/sources.listbak

sed -i '1r deb.txt' /etc/apt/sources.list

mkdir /etc/ocsinventory-agent

cp -f ./cacert.pem /etc/ocsinventory-agent/

apt-get -y install ntpdate  dmidecode libxml-simple-perl libnet-ip-perl libwww-perl perl libnet-ssleay-perl libcrypt-ssleay-perl libnet-snmp-perl libproc-pid-file-perl  libproc-daemon-perl net-tools libsys-syslog-perl pciutils smartmontools read-edid nmap make

stat=`echo $?`

clear

cp -f /etc/apt/sources.listbak /etc/apt/sources.list

fi

# RedHat OS ********************************

if [ $OS -eq 1 ] ;then

echo "Redhat Linux "

sleep 1

mkdir -p /etc/ocsinventory-agent

cp -f ./cacert.pem /etc/ocsinventory-agent/

yum -y --nogpgcheck localinstall ./packages/*.rpm

stat=`echo $?`

fi

# sync time ****************************************

echo "sync time......"

ntpdate 210.72.145.44

ntpdate cn.pool.ntp.org

# make && make install *******************************

if [ $stat -eq 0 ] ;then

# read input Parameter

clear

while [ 1 ]

do

echo -en "\033[47;34;7mWarning: Enter TAG  on this machine :\033[0m"

read tag

leng1=`echo ${tag} | wc -L|bc`

if [ $leng1 -lt 5 ]

then

clear

echo -e "\033[40;36;7mWarning:TAG more than 5 length.:\033[0m"

else

break

fi

done

# read input time for cron

while [ 1 ]

do

echo -en "\033[47;34;7mHello: How many hours do you want executive OCS Agent ?\033[0m [1-23]/ [2]?:"

read time1

if [ -z "$time1" ];then

time1=2

fi

time2=`echo ${time1} |bc`

if [ $time2 -ge 1 -a $time2 -le 23 ]

then

time3=$time2

break

else

echo "Warning: input error ,please try again."

fi

done

cd Ocsinventory-Unix-Agent-2.1.1

make clean

env PERL_AUTOINSTALL=1 perl Makefile.PL && make && make install && perl postinst.pl --nowizard --remove-old-linux-agent --server=https://your_OCSNG-Server_IP/ocsinventory --crontab --tag=$tag --debug --logfile=/etc/ocsinventory-agent/ocs.log --ca=/etc/ocsinventory-agent/cacert.pem --snmp --now

grep Cannot  /etc/ocsinventory-agent/ocs.log > /dev/null 2>&1

stat2=`echo $?`

else

clear

echo "warning:Dependency relationship No solution ."

exit 2

fi

# set for cron *********************************************************

if [ $stat2 -ne 0 ] ;then

clear

echo  "install ocsinventory-agent  Successful !"

sleep 2

# modify ocsNG agent conf.file debug=0

sed -i "s#debug=1#debug=0#g" /etc/ocsinventory-agent/ocsinventory-agent.cfg

a=`date +%M`

b=`echo "$a"|bc`

sed -i '2d' /etc/cron.d/ocsinventory-agent

echo "$b */$time3 * * * root /usr/local/bin/ocsinventory-agent --lazy > /dev/null 2>&1" >> /etc/cron.d/ocsinventory-agent

stat3=`echo $?`

if [ $stat3 -eq 0 ] ;then

if [ $OS -eq 2 ] ;then #debian

/etc/init.d/cron restart

stat4=`echo $?`

fi

if [ $OS -eq 1 ] ;then #redHat

service crond reload

stat4=`echo $?`

fi

fi

else

clear

date

echo "Warning:install error ,please try again  [ ./install.sh ]"

exit 2

fi

if [ $stat4 -eq 0 ] ;then

clear

echo "your machine TAG :$tag"

grep debug=0 /etc/ocsinventory-agent/ocsinventory-agent.cfg

echo -en "install ocsinventory-agent Successful!\n\nThe current time: "

tail -n 1 /etc/cron.d/ocsinventory-agent | cut -d " "  -f1

else

clear

echo "Warning:cron error "

exit 2

fi

=======一键自动化安装脚本结束==============================================

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值