步骤1 编写脚本 直接在根目录 vim openoffice.sh
#!/usr/bin/bash OPENOFFICEPID=`ps -ef|grep "/opt/openoffice4/program/soffice"|grep -v grep|grep -v grep|awk '{print $2}'` if [ ! -n "$OPENOFFICEPID" ];then echo "OPENOFFICEPID is empty" echo "start openoffice" nohup /opt/openoffice4/program/soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;StarOffice.Service" -nofirststartwizard & else echo "OPENOFFICEPID is $OPENOFFICEPID is started!" fi退出保存 :wq 步骤2 将openoffice.sh脚本放置在服务器根目录下面,如图所示:
步骤3 赋权限
root@iZbp1aw7yt2qgbbrz5rs6pZ:/# chmod a+x openoffice.sh步骤4 编辑crontab文件
root@iZbp1aw7yt2qgbbrz5rs6pZ:/# crontab -e编辑内容如下
* * * * * sh /openoffice.sh注:每1分钟执行一次此脚本,可以根据实际需要进行
步骤5 验证: 查看当前的启动的openOffice
root@iZbp1aw7yt2qgbbrz5rs6pZ:/# ps -ef|grep /opt/openoffice4/program/soffice删除后
–将openoffice所有进程杀掉
ps -ef|grep "/opt/openoffice4/program/soffice"|grep -v grep|grep -v grep|awk '{print $2}' | xargs kill查看是否还在运行:
netstat -nlp | grep 8100等一分钟后查看(通过对比时间) 到这里sh脚本就执行成功啦!有需要的可以去试试
