Chinaunix首页 | 论坛 | 博客
  • 博客访问: 115934
  • 博文数量: 38
  • 博客积分: 2111
  • 博客等级: 大尉
  • 技术积分: 395
  • 用 户 组: 普通用户
  • 注册时间: 2010-02-06 13:04
文章分类

全部博文(38)

文章存档

2012年(4)

2010年(34)

我的朋友

分类: LINUX

2010-05-17 15:54:46

执行脚本方法

 

full path       /tmp/test/a.sh

相对路径            cd  /tmp/test  ;   ./a.sh

把执行脚本目录添加到环境中

 

[root@station10 test]# vi /etc/profile   <--- 所有人都能够获得

[root@station10 test]# vi $HOME/.bash_profile  <- 个人用户信息

 

修改后,令环境生效

    1. 重新登录

    2. source /etc/profile   ||   .  /etc/profile

 

 

 

[root@station10 test]# number=(1 2 3 4 5)

[root@station10 test]# echo ${number[1]}

 

[root@station10 test]# name=( black [3]=red  [5]=white blue )

[root@station10 test]# echo ${name[3]}

red

[root@station10 test]# echo ${name[5]}

white

 

 

 

if [ ]

then

 

else

 

fi

 

字符

 ==  !=  >  <   >=   <=

纯数字

 -eq -ne -gt -lt -ge -le

特殊

 -f     文件是否存在

 -z     变量值是否存在

 -d     目录

 -L     链接文件

 -b     块设备文件

 -c     字符设备文件

 -S     socket 文件

 

 针对文件的属性

    -O (owner)

    -G (group)

 文件比较

    -nt     那个新

    -ot     那个旧

    -ef     是否相同文件索引节点

        假如是软建立

         True  if  file1  and file2 refer to the same device and

              inode numbers.

 

    -r 

    -w 

    -x  执行

 

    -n  判断字符长度不为0

 

 

特殊比较

alnum alpha ascii blank cntrl digit graph  lower  print punct space upper word xdigi

 

[[:digit:]]  [[:alpha:]]  [[:lower:]]  <- 只判断一个字符

    字符 或 纯字母判断例子

 

=~  正则表达式 必须使用  if [[  xxxx  xxxx   ]]

 

 

颜色控制

\\033[0;31m     红色

\\033[0;32m

\\033[0;33m

\\033[0;34m     蓝色

\\033[0;35m

\\033[0;36m

\\033[0;37m

\\033[0;38m     黑色

\\033[0;39m

\\033[0;40m

\\033[0;41m

\\033[0;42m

\\033[0;43m

\\033[0;44m

..

\\033[0;48m     黑色

 

 

[root@station10 /]# 1. 获得系统的环境变量

[root@station10 /]# $UID  $USER

[root@station10 /]# 2. 颜色控制

[root@station10 /]# 3. 如何令用户登录后 自动执行脚本

 

 

 

if [ ]

then

    if [ ]

    then

   

    else

 

    fi

else

 

fi

 

if [ ]

then

 

elseif

then

 

else

 

 

fi

 

 

if [ A ] && [ B ]   A B 都为真返回真, 否则返回假

if [ A -a B ]

 

if [ A ] || [ B ]  A B 都为假,返回假, 否则返回真

if [ A -o  B ]

 

 

计算 2010-06-11 距离现在还剩下多少天

然后每个用户登录都能够自动看到返回的日期信息

 

 

检测网络是否正常

(是否掉线,是否能够连接网关,是否能够获得 DNS 解析,是否能够访问互联网)

返回上面 4 个结果到屏幕

 

3. 检测 httpd 服务是否工作正常,

假如不正常,重启服务,把当前时间记录到 service 文件

正常不操作

 

4. 检测 IP 地址是否发生变化

 

------------------------------------------------------

循环语法

for  xxx in xxxx

do

 

done

 

--------------------------

for a in 1 2 3 4 5

do

    echo $a

done

循环 5

 

while [ ]       <- 为假执行循环

do

    为真跳出循环

done

--------------------------

实例:

 

#!/bin/bash

a=3

b=5

if [ $a >  $b ]

then

    echo yes

else

    echo no

fi

 

c="y"

d="z"

if [ $c ==  $d ]

then

    echo yes

else

    echo no

fi

 

 

if [ -f  "/tmp/test/newuser.txt" ]

then

    echo file exits

else

    echo file is not exits

fi

 

if [ -d "/tmp/test/aaa" ]

then

    echo dir exits

else

    echo dir not exits

fi

 

f=''

g='5'

 

if [ -z  $f ]

then

    echo empty

else

    echo full

fi

 

 

if [ -z  $g ]

then

    echo g is empty

else

    echo g is full

fi

echo --------------------------

 

if [  -O "/tmp/test/terry" ]

then

    echo true

else

    echo false

fi

 

 

 

 

echo --------------------------

if [ "/tmp/test/567" -nt "/tmp/test/test" ]

then

    echo yes

else

    echo no

fi

echo --------------

if [ "/tmp/test/soft"  -ef  "/tmp/test/hard" ]

then

    echo yes

else

    echo no

fi

 

 

if [ "/tmp/test/hard"  -ef  "/tmp/test/passwd" ]

then

    echo yes

else

    echo no

fi

echo ------------------------------

 

h=3

if  [[ $h == [[:digit:]] ]]

then

    echo yes

else

    echo no

fi

 

echo ========================

a="awoeryweoiruwoeiuewioru"

 

if [[ $a =~ ^w  ]]

then

    echo yes

else

阅读(885) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:供港澳蔬菜检验检疫监管系统使用报告

给主人留下些什么吧!~~