分页: 1 / 1

[原创]整理了一个Ubuntu的一个安装的小脚本

发表于 : 2008-06-26 16:30
greegree
整理了一个Ubuntu的一个安装的小脚本。

这个脚本可以直接使用或者加一个参数。直接使用的时候进行apt-get的update和upgrade,添加一个参数的时候进行安装此参数代表的软件包。

做这个脚本关键是想把每次执行apt-get的log过程输出到固定目录下以当前时间命名的文件中。方便日后查看。

代码: 全选


#!/bin/bash 

#
# param
#    $1 - package to install
# 

DATELOG=$(date +%Y_%m_%d_%H%M) 

LOG=/media/EXCHANGE/ubuntu_update_log 

CURDIR=$(pwd) 

echo 
echo "****************************************"
echo " 1 : do the dir utils "
echo "****************************************"
echo 
if [ -d $LOG ];then
    echo "local log dir already exist"
else
    echo "local log dir not exist, mkdir it's"
    mkdir $LOG -p
fi 

if [ $# -eq 1 ];then 

    echo 
    echo "****************************************"
    echo " 1.1 : apt-get update the ubuntu "
    echo "****************************************"
    echo 
    sudo apt-get update -y 2>&1 | tee -a $LOG/apt-get_update_$DATELOG.log
    sudo apt-get upgrade -y 2>&1 | tee -a $LOG/apt-get_upgrade_$DATELOG.log
    else 
        if [ $# -eq 2 ];then
            echo 
            echo "****************************************"
            echo " 1.2 : apt-get install the package "
            echo "****************************************"
            echo 
            sudo apt-get install $2 -y 2>&1 | tee -a $LOG/apt-get_install_$2_$DATELOG.log
        fi 
fi

cd $CURDIR
示例:

代码: 全选

./test -- 进行update和upgrade

代码: 全选

./test gcc -- 安装gcc
修改了一下下
原来的脚本不怎么好用,重新修改了判断条件。
另外,我的板子跑ubuntu的确有点慢了,一般装个啥费劲很了,所以才整了这么个生成log文件的脚本。

代码: 全选

#!/bin/bash

#
# param
#	$0~$9 - package to install
#

DATELOG=$(date +%Y_%m_%d_%H%M)

LOG=/media/EXCHANGE/ubuntu_update_log

CURDIR=$(pwd)

echo 
echo "****************************************"
echo " 1 : do the dir utils "
echo "****************************************"
echo 
if [ -d $LOG ];then
	echo "local log dir already exist"
else
	echo "local log dir not exist, mkdir it's"
	mkdir $LOG -p
fi

if [ $# -eq 0 ];then
	echo
	echo "*******************************"
	echo "apt-get update the system "
	echo "*******************************"
	echo 
	sudo apt-get update -y --force-yes 2>&1 | tee -a $LOG/apt-get_update_$DATELOG.log
	DATELOG=$(date +%Y_%m_%d_%H%M)
	sudo apt-get upgrade -y --force-yes 2>&1 | tee -a $LOG/apt-get_upgrade_$DATELOG.log
else
	echo 
	echo "*******************************"
	echo " apt-get install ${*} "
	echo "*******************************"
	echo 
	declare -i i=0
	declare -i n=$#
	while [ $i -lt $n ]
	do
		echo 
		echo "*******************************"
		echo " apt-get install $1 "
		echo "*******************************"
		echo 
		i=i+1
		DATELOG=$(date +%Y_%m_%d_%H%M)
		sudo apt-get install $1 -y --force-yes 2>&1 | tee -a $LOG/apt-get_install_$1_$DATELOG.log
		shift
	done
fi 
保存为refresh_system
使用:
1)更新系统:

代码: 全选

./refresh_system
2)安装软件

代码: 全选

./refresh_system a b c d 

发表于 : 2008-06-26 16:32
BigSnake.NET
看 /var/log/dpkg.log 和 apt 的log

发表于 : 2008-06-26 16:43
bones7456
汗..就为了日志?

发表于 : 2008-06-26 16:55
eexpress
man logrotate 吧。log管理机制范围多的。不要自己去搞。