Download *.dmg file and open it then click install script;
For the App that can only be installed from *.dmg file, there’s a better way to automate the install process.
The second way includes following steps:
Download the package-*.dmg file;
Mount *.dmg file to file system- e.g /Volumes/app_name
Install app with the installer or *.pkg file
Given we want to install vagrant:
For the first step, say curl -O download_link for people don’t have tools like wget. If you have wget, say installed through brew brew install wget, you can just use wget.
For the second step, we can use hdiutil command to mount the dmg file to /Volumes.
For the last step, the installer in osx perfectly solve the issue. Command like:
And it would use the administrator previlidge to install the package.
For the whole install process, the only thing you need to do is type in the password. And this is an example for fulfilling the automation. Surely it can be improved more genericly, for I only use this for vagrant session.^_^
Nowadays, lots of people would use video to record a tutorial for demonstrating. It’s cool for vividly showing everything to people. The only issue is that file size of video is relatively large. From this point of view, the old way of recording actions from console might be a better idea.
script and scriptreplay are console recording/playing tools. script would record time and actions of current session in two different files. And scriptreplay would play those actions again in the console。 It’s quite easy to use these tools, just like the following:
12345678910111213141516
[vagrant@bogon shell]$ script -t 2>timing.log -a output.session
Script started, file is output.session
[vagrant@bogon shell]$ ls -al .
total 24
drwxrwxr-x 2 vagrant vagrant 4096 Nov 5 09:37 .
drwx------ 4 vagrant vagrant 4096 Nov 4 12:15 ..
-rw-rw-r-- 1 vagrant vagrant 4400 Nov 5 09:42 output.session
-rw-rw-r-- 1 vagrant vagrant 55 Nov 4 12:16 test.txt
-rw-rw-r-- 1 vagrant vagrant 111 Nov 5 16:21 timing.log
[vagrant@bogon shell]$ cd /tmp/
[vagrant@bogon tmp]$ ls
input.txt ks-script-iuQ695 ks-script-iuQ695.log output.txt stderr try.txt vboxguest-Module.symvers yum.log
[vagrant@bogon tmp]$ touch something.txt
[vagrant@bogon tmp]$ exitexitScript done, file is output.session
So the -t would record the time and -a would record actions to different files. In the command below, we also redirect the error message to timing.log file.
And if we want to replay it, just use the scriptreplay command, like this:
1
scriptreplay timing.log output.session
Then it would play what you have done before.
The thing you need to pay attention to is that such recording just happen in a session, so actions like switching user to do something would break that, to my understanding. Personally, I would use su user -c 'commands' to solve this issue.
It might not be a feature used often times, but it probably would help if you want to share or show actions you’ve done to others.
ARITHMETIC EVALUATION
The shell allows arithmetic expressions to be evaluated, under certain circumstances (see the let and declare builtin commands and Arithmetic Expansion).
Evaluation is done in fixed-width integers with no check for overflow, though division by 0 is trapped and flagged as an error. The operators and their
precedence, associativity, and values are the same as in the C language. The following list of operators is grouped into levels of equal-precedence opera-
tors. The levels are listed in order of decreasing precedence.
id++ id--
variable post-increment and post-decrement
++id --id
variable pre-increment and pre-decrement
- + unary minus and plus
! ~ logical and bitwise negation
** exponentiation
* / % multiplication, division, remainder
+ - addition, subtraction
<< >> left and right bitwise shifts
<= >= < >
comparison== != equality and inequality
& bitwise AND
^ bitwise exclusive OR
| bitwise OR
&& logical AND
|| logical OR
expr?expr:expr
conditional operator= *= /= %= += -= <<= >>=&= ^=|= assignment
expr1 , expr2
comma
可以看到涵盖了通用的编程语言中的数学运算方式,那么在shell中可以通过那些命令来进行计算呢?
declare: 声明变量同时定义其属性。
1234567891011
#!/bin/bashn=1*2*9/3
echo$ndeclare -i n
n=1*2*9/3
echo$nresult:
1*2*9/3
6
[vagrant@localhost ~]$ sudo yum shell
Loaded plugins: fastestmirror
Setting up Yum Shell
> search vim-common
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.stuhome.net
* updates: mirrors.btte.net
N/S Matched: vim-common ==============================================================================vim-common.x86_64 : The common files needed by any version of the VIM editor
[vagrant@localhost ~]$ sudo yum history info 3
Loaded plugins: fastestmirror
Transaction ID : 3
Begin time : Sat Mar 9 15:50:00 2013
Begin rpmdb : 239:6f5a8ecd22e6f0a663940801ef56d66b2ad40228
End time : 15:50:07 2013(7 seconds)End rpmdb : 255:92e8267085fc364911baebaf646b14856fb20498
User : <veewee>
Return-Code : Success
Command Line : -y install puppet facter
Transaction performed with:
Installed rpm-4.8.0-32.el6.x86_64 @anaconda-CentOS-201303020151.x86_64/6.4
Installed yum-3.2.29-40.el6.centos.noarch @anaconda-CentOS-201303020151.x86_64/6.4
Installed yum-plugin-fastestmirror-1.1.30-14.el6.noarch @anaconda-CentOS-201303020151.x86_64/6.4
Packages Altered:
Dep-Install augeas-libs-0.9.0-4.el6.x86_64 @base
Dep-Install compat-readline5-5.2-17.1.el6.x86_64 @base
Dep-Install dmidecode-1:2.11-2.el6.x86_64 @base
Install facter-1:1.6.17-1.el6.x86_64 @puppetlabs
Dep-Install hiera-1.1.2-1.el6.noarch @puppetlabs
...
既然可以记录Transaction,那么势必也会提供undo和redo的功能:
12
sudo yum history undo 7#将Transaction 7中安装的所有软件都删除 sudo yum history redo 8#将Transaction 7中删除的软件重新安装
对于系统管理员来说,这应该算得上是个比较有用的命令。前面提到yum的交易记录数据库文件保存在 /var/lib/yum/history/下面,如果想将Transction记录到新的db文件中,可以用yum history new,它会清空/var/lib/yum/history/目录,然后新建db文件。想打开某个history记录文件可以用yum load-transaction file_name。
yum provides : 通过软件安装后的可执行文件,反查安装它的package
1234567891011121314151617
vagrant@localhost ~]$ yum provides /usr/bin/vim
1:vim-enhanced-7.2.411-1.8.el6.x86_64 : A version of the VIM editor which includes recent enhancements
Repo : installed
Matched from:
Other : Provides-match: /usr/bin/vim
[vagrant@localhost ~]$ yum provides wget
wget-1.12-1.8.el6.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
Repo : installed
Matched from:
Other : Provides-match: wget
[vagrant@localhost ~]$ yum provides /*/vi
1:vim-minimal-7.2.411-1.8.el6.x86_64 : A minimal version of the VIM editor
Repo : installed
Matched from:
Other : Provides-match: /bin/vi
When we talking about History database, we are generally saying the database that deposit the actions performed on other databases by application. It is freaking important for recording the critical action that performed by users in both business and development point of view. With the help of ChangeLog database, we can easily track that an purchased transaction has or has not happened at certain time, thus by querying this table, we will 100% sure if the user wants to confirm with the transaction.
A typical table, say ChangeLog in History database, would have such kind of schema:
The schema shows that it would record action done on some table by someone from certain value to other value on certain time. Two columns, TableName and ForeignKey, are indexed, which would be faster if you take those two in the where clause. The thing you need to aware is that index of ForeignKey is only working when TableName is also existed in the where clause.
History database is normally huge and rarely has replica, as we can imagine. The reason, I suspect, is the changing-write/read operation much more frequently than other tables. Normally, it has several following characters:
Query/Scan/Join operation could cause performance on database for it has large bunch of data;
It’s pretty pretty important that I don’t need to talk about this twice;
Things in the history database is genuine, application or log can fake but the history table does not lie;
Since it’s might be the only database, clearly it’s not
Due to the importance of History database, few people would have access. But there gonna be chance that you would talk to it. And the following are the tips I learned from a senior developer about interacting with History database:
Pair with someone who are experienced and can make sure the query you write would not do harm to the database;
Check the ChangeLog table schema first, attention whether it has some columns indexed;
Use “–“ in the beginning to comment out your query in case if you hit enter before you complete the query;
To “explain" the query you want to run firstly, to see whether the query would happen in a very large dataset, if it is, then you need to consider the consequent for running the query.
1234567
mysql> Explain select * from ChangeLog where TableName='' and ForeignKey='';+----+-------------+-----------+------+---------------+------+---------+-------------+------+-------------+
| id | select_type | table |type| possible_keys | key | key_len | ref | rows | Extra |+----+-------------+-----------+------+---------------+------+---------+-------------+------+-------------+
|1| SIMPLE | ChangeLog | ref | idx1 | idx1 |86| const,const |61| Using where |+----+-------------+-----------+------+---------------+------+---------+-------------+------+-------------+
1 row in set(0.47 sec)
What we can see from the result of explain is that the query would happen only in 61 rows, which would barely cause performance issue on the database. Of course, good to go.
[vagrant@localhost ~]$ yum -v grouplist kde\*Config time: 0.009
Yum Version: 3.2.29
Setting up Group Process
rpmdb time: 0.001
group time: 0.159
Available Groups:
KDE Desktop (kde-desktop)# KDE Desktop 组的id 就是(kde-desktop)Done
yum info package_name 等同于rpm -q --info package_name
vagrant@localhost ~]$ yum info vim-common
Installed Packages
Name : vim-common
Arch : x86_64
Epoch : 2
Version : 7.2.411
Release : 1.8.el6
Size : 17 M
Repo : installed
From repo : base
Summary : The common files needed by any version of the VIM editor
URL : http://www.vim.org/
License : Vim and GPLv2+ and BSD and LGPLv2+ and Open Publication
Description : VIM (VIsual editor iMproved) is an updated and improved version of the
: vi editor. Vi was the first real screen-based editor for UNIX, and is........
可以看到package相关的所有信息,
罗列packages信息:
1
yum list [available|installed|extras|updates|obsoletes|all|recent][pkgspec]
1234567891011121314151617
yum list available 列出当前enable的repo中所有可用package
yum list installed 列出当前系统中已经安装的package
yum list extras 列出已安装的package中不在enable的repo中的package
yum list updates 列出当前enable的repo中可以提供更新的package
yum list obsoletes 列出enable的repo中或者已安装的package中被淘汰的package
yum list all 列出所有enable的repo中的package
yum list recent 列出所有enable的repo中最近一周添加的package
yum list installed "krb?-*" 以上所有的list命令都支持通配符,罗列相关的package信息
yum list package spec 为特定的package列出相关信息,比如列出glibc的信息
[vagrant@localhost yum.repos.d]$ yum list glibc
Installed Packages
glibc.x86_64 2.12-1.107.el6 @anaconda-CentOS-201303020151.x86_64/6.4
Available Packages
glibc.i686 2.12-1.107.el6_4.2 updates
glibc.x86_64 2.12-1.107.el6_4.2 updates
yum list \*.i686 #glob expression
vagrant@localhost yum.repos.d]$ yum search vim=================================================================================== Matched: vim====================================================================================vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
vim-common.x86_64 : The common files needed by any version of the VIM editor
vim-enhanced.x86_64 : A version of the VIM editor which includes recent enhancements
vim-minimal.x86_64 : A minimal version of the VIM editor
[vagrant@localhost yum.repos.d]$ yum search "vi editor"#只需要描述软件提供的功能,便可以查找出提供该功能的软件包============================================================================== N/S Matched: vi editor===============================================================================vim-X11.x86_64 : The VIM version of the vi editor for the X Window System
[vagrant@localhost ~]$ yum info yum-utils
.......
Description:
yum-utils is a collection of utilities and examples for the yum package manager. It includes utilities by different authors that make yum easier and more powerful to use. These tools include:
: debuginfo-install, find-repos-of-install, repodiff,
: needs-restarting, package-cleanup, repoclosure,
: repo-graph, repomanage, repoquery, repo-rss, reposync,
: repotrack, show-installed, show-changed-rco, verifytree,
: yum-builddep, yum-complete-transaction, yumdownloader,
: yum-config-manager, yum-debug-dump,
: yum-debug-restore and yum-groups-manager.
[vagrant@localhost ~]$ sudo yum install yum-aliases #安装插件/etc/yum.conf
plugins=1/0 #使用/不试用所有的插件/etc/yum/pluginconf.d/aliases.conf
[main]enabled=1/0 #使用/不试用aliases插件# conffile - config. file to use# <default> = /etc/yum/aliases.conf/etc/yum/aliases.conf
FORCE --skip-broken --disableexcludes=all
up upgrade
in install
rm remove
.........
/etc/yum/aliases.conf中定义了yum很多命令的alias,比如 in => install, 这样我就可以用yum in package_name,少敲几个字,节省体力。alias到option的用处会更大些,比如上面的FORCE。乐意的话,我们也可以按照个人喜好自己定制这个aliases的配置文件。
[yum]# These are the top level things to do with yum, we don't list Eg. libselinux# even though that's require by rpm(-libs).run_with_packages=truepkglist= glibc, sqlite, libcurl, nss,
yum-metadata-parser,
rpm, rpm-libs, rpm-python,
python,
python-iniparse, python-urlgrabber, python-pycurl
[vagrant@localhost ~]$ sudo yum remove vim-common
Setting up Remove Process
Resolving Dependencies
--> Running transaction check
---> Package vim-common.x86_64 2:7.2.411-1.8.el6 will be erased
--> Processing Dependency: vim-common = 2:7.2.411-1.8.el6 for package: 2:vim-enhanced-7.2.411-1.8.el6.x86_64
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.2.411-1.8.el6 will be erased
--> Finished Dependency Resolution
Error: Trying to remove "vim-common", which is protected
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest