背景
- 运维:
- 目标:保障系统长期、稳定、安全运行
- 工作内容;安装、配置、备份、监控、邮件报警、自动报警、
- 物理世界
- CPU
- 内存
- 网卡
- 磁盘
- 资源角度
- 计算
- 存储
- 网络
一. 什么是shell
- 脚本语言
- 查看所有的脚本
cat /etc/shells
- 做什么
- 自动化批量系统初始化 (update,软件安装,时区设置,安全策略,防火墙、端口转发等)
- 自动化批量软件部署 (LAMP,Tomcat,Nginx)
- 管理应用程序
- 自动化备份恢复程序(MySQL 完全、增量备份)
- 快捷键
- 搜索一条历史命令
- logout
- 最前面
- 最后面
- 删除后面
二. 什么是解释器
- 用来指定下文内容的解释器
- vim explain.sh
- chmod a+x explain.sh
- ./explain.sh
#! /bin/sh
echo hello
- pyrhon 解释器
- vim explain.py
- which python
- chmod a+x explain.py
- ./explain.py
#! /usr/bin/python
print ("Hello, Python!")
- vim explain-no.py
- python explain-no.py
- ./explain-no.py
此时的解释器是bash
print ("Hello, Python!")
- 在一个解释器中请引入其他解释器
- vim other.sh
- chmod a+x other.sh
#!/bin/bash
## &>/dev/null 表示将输出的结果重定向
ping -c1 www.baidu.com &>/dev/null && echo "baidu is up" || echo "baidu is down"
/usr/bin/python <<-EOF
print "hello world"
print "hello world"
print "hello world"
EOF
- 默认shell 是 bash
- vim explain-no.sh
- chmod a+x explain-no.sh
- ./explain-no.sh
- sh explain-no.sh
echo hello
默认的shell 是bash,定义在/etc/passwd中
- /etc/passwd 定义用户登录后使用的shell
以下表格摘录自《Unix环境高级编程》
说明 | struct passwd成员 | FreeBSD 5.2.1 | Linux2.4.22 | MAC OS X 10.3 | Solaris 9 |
---|---|---|---|---|---|
用户名 | char *pw_name | * | * | * | * |
加密口令 | char *pw_passwd | * | * | * | * |
数值用户ID | uid_t pw_uid | * | * | * | * |
数值组ID | gid_t pw_gid | * | * | * | * |
注释字段 | char *pw_gecos | * | * | * | * |
初始工作目录 | char *pw_dir | * | * | * | * |
初始shell | char *pw_shell | * | * | * | * |
用户访问类 | char *pw_class | * | * | ||
下次更改口令时间 | ti |