Linux下脚本的编写和执行

Posted on 2012-11-07 11:52  JasmineLiu  阅读(550)  评论(0编辑  收藏  举报

在linux终端执行语句比较麻烦 ,这是我们就可以写一个脚本,通过执行该脚本来执行脚本中的操作。

比如登陆pg时:

我们可以在/root/Desktop下创建一个文本文件,命名为pg_log;

在里面编写脚本:

        cd /usr/local/pgsql/bin 

       ./pg_ctl -D ../data -l logfile start

       ./psql postgres postgres

并授予pg_log权限

[root@localhost Desktop]$ chown postgres pg_log

[root@localhost Desktop]$su postgres

[postgres@localhost Desktop]$chomd 777 pg_log

(可以通过ll命令查看pg_log的权限。)

每次需要登陆pg时就直接执行脚本即可。

[root@localhost Desktop]$su postgres

[postgres@localhost Desktop]$./pg_log

这样就可以直接登录pg,而不需要挨个执行那些命令了。

 

Copyright © 2024 JasmineLiu
Powered by .NET 8.0 on Kubernetes