linux下通过 sh 打开一个程序,如何vs 编写 linux程序sh脚本。

请教:如何在linux服务器上实现一个程序,该程序可启动远程linux客户端上的一个脚本(sh后缀)的执行
[问题点数:40分,结帖人jackyloncoln]
本版专家分:0
CSDN今日推荐
本版专家分:0
本版专家分:345
本版专家分:978
本版专家分:0
本版专家分:9837
2007年8月 Linux/Unix社区大版内专家分月排行榜第一
2007年9月 Linux/Unix社区大版内专家分月排行榜第二2007年7月 Linux/Unix社区大版内专家分月排行榜第二
2010年6月 Linux/Unix社区大版内专家分月排行榜第三2008年4月 Linux/Unix社区大版内专家分月排行榜第三2008年3月 Linux/Unix社区大版内专家分月排行榜第三
本版专家分:0
本版专家分:9837
2007年8月 Linux/Unix社区大版内专家分月排行榜第一
2007年9月 Linux/Unix社区大版内专家分月排行榜第二2007年7月 Linux/Unix社区大版内专家分月排行榜第二
2010年6月 Linux/Unix社区大版内专家分月排行榜第三2008年4月 Linux/Unix社区大版内专家分月排行榜第三2008年3月 Linux/Unix社区大版内专家分月排行榜第三
匿名用户不能发表回复!|
CSDN今日推荐Linux平台下启动java程序的脚本编写Linux平台下启动java程序的脚本编写百度经验百家号Java在window下的脚本很多人都会,因为大家都在window平台下开发。但是一旦上生产系统就要会更换到Linux平台下。毕竟java是跨平台的吗?可是,程序是跨平台的,启动脚本却是和系统平台紧密相关的。我就教教大家如何写linux平台下java的启动脚本首先,我们登录一个linux平台这里大家使用ssh客户端远程登录系统。接着,创建脚本文件&startServer.shStart脚本&对应&启动脚本接着,我们来分析startServer.sh脚本文件开头两个部分,声明脚本解析引擎为sh下面是说明本脚本的说明性的注释文字。接着,脚本分析程序是否已经启动。如果启动则退出脚本,并提示用户程序以及启动接着,我们配置java启动的相关参数主要是配置claspath。(注意必须包含&当前&目录&.&)最后,切换到运行目录,并启动java程序本文由百家号作者上传并发布,百家号仅提供信息发布平台。文章仅代表作者个人观点,不代表百度立场。未经作者许可,不得转载。百度经验百家号最近更新:简介:解决你所有的生活难题作者最新文章相关文章Linux中执行shell脚本的4种方法总结
转载 &更新时间:日 08:41:25 & 投稿:junjie
这篇文章主要介绍了Linux中执行shell脚本的4种方法总结,即在Linux中运行shell脚本的4种方法,需要的朋友可以参考下
bash shell 脚本的方法有多种,现在作个小结。假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限。
方法一:切换到shell脚本所在的目录(此时,称为工作目录)执行shell脚本:
cd /data/shell
./hello.sh
./的意思是说在当前的工作目录下执行hello.sh。如果不加上./,bash可能会响应找到不到hello.sh的错误信息。因为目前的工作目录(/data/shell)可能不在执行程序默认的搜索路径之列,也就是说,不在环境变量PASH的内容之中。查看PATH的内容可用 echo $PASH 命令。现在的/data/shell就不在环境变量PASH中的,所以必须加上./才可执行。
方法二:以绝对路径的方式去执行bash shell脚本:
/data/shell/hello.sh
方法三:直接使用bash 或sh 来执行bash shell脚本:
cd /data/shell
bash hello.sh
cd /data/shell
sh hello.sh
注意,若是以方法三的方式来执行,那么,可以不必事先设定shell的执行权限,甚至都不用写shell文件中的第一行(指定bash路径)。因为方法三是将hello.sh作为参数传给sh(bash)命令来执行的。这时不是hello.sh自己来执行,而是被人家调用执行,所以不要执行权限。那么不用指定bash路径自然也好理解了啊,呵呵……。
方法四:在当前的shell环境中执行bash shell脚本:
cd /data/shell
. hello.sh
cd /data/shell
source hello.sh
前三种方法执行shell脚本时都是在当前shell(称为父shell)开启一个子shell环境,此shell脚本就在这个子shell环境中执行。shell脚本执行完后子shell环境随即关闭,然后又回到父shell中。而方法四则是在当前shell中执行的。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具您所在位置: &
&nbsp&&nbsp&nbsp&&nbsp
linux sh脚本编程(Linux sh scripting).doc 7页
本文档一共被下载:
次 ,您可全文免费在线阅读后下载本文档。
下载提示
1.本站不保证该用户上传的文档完整性,不预览、不比对内容而直接下载产生的反悔问题本站不予受理。
2.该文档所得收入(下载+内容+预览三)归上传者、原创者。
3.登录后可充值,立即自动返金币,充值渠道很便利
linux sh脚本编程(Linux sh scripting)
你可能关注的文档:
··········
··········
linux sh脚本编程(Linux sh scripting)
Linux, sh scripting
While there are various graphical interface tools in the Linux system, sell is still a very flexible tool. The Shell is not just a collection of commands, but a great programming language. You can automate a lot of tasks by using shells, which are particularly good at system administration tasks, especially those that are easy to use, maintainability, and portability more important than efficiency.
Below, let's look at how the shell works:
Create a script
There are a lot of different shells in Linux, but we usually do shell programming with the bourne again shell, because bash is free and easy to use. So the scripts I've provided in this article are using bash (but in most cases, these scripts can also run in bash's older sister, bourne shell).
Like any other language, we use any kind of text editor, such as nedit, kedit, emacs, vi, to write our shell program. The program must begin with the following line (the first line of the file is required) :
#! / bin/sh
Sign #! The procedure used to tell the system that the following parameters are used to execute the file. In this case, we use/bin/sh to execute the program.
When the script is edited, it must be executed if the script is to be executed.
To make the script executable:
Chmod + x filename
Then, you can execute your script by typing:. / filename.
annotation
When you do shell programming, write the comment in the # opening sentence until the end of the line. We sincerely recommend that you use comments in your programs. If you use annotations, you can understand how the script works and how it works in a very short time, even if you don't use it for quite a long time.
You must use variables in other programming languages. In shell programming, all variables are composed of strings, and you don't need to declare variables. To assign a value to a variable, you can write:
Variable name = value
You can add a dollar sign ($) to the variable in front of the v
正在加载中,请稍后...[转载]linux下写一个.sh的脚本执行java程序
今天大概耗费了快一天的时间研究怎么用脚本执行java程序,终于实现了,分享一下
(1)在linux下写一个.sh文件
(2)文件内容如下:
#!/bin/sh & &
& & //bash文件头
APP_HOME=/home/blmcrm/crm/A &
& &//要执行的java文件中bin文件的上一个目录,我的目录
&是/home/blmcrm/crm/A/bin/blm......(后面不写了),总之就是写bin目录
&前面的部分,因为jar包在bin目录里面,如果不在bin里面,也如此改一下
CLASSPATH=$APP_HOME/bin & &
//bin目录当然是包含jar包的目录啦
for i in "$APP_HOME"/bin/*.jar &
&//引进所有的jar包,这里用的循环,当然也可以按照这个格式一个一个
&CLASSPATH="$CLASSPATH":"$i"
//环境变量就这格式
export CLASSPATH=.:$CLASSPATH &
&//不写这个可能会说找不到main类
echo ${CLASSPATH} & &
& &//打印环境变量,可以不写
java -Xms50m -Xmx250m
org.gdh.blm.exec.Syslog_csv&
exit(结束)
& & //执行java程序, 其中-Xms50m
-Xmx250m是运行内存什么的设置,后面的是bin目录以后一直到.class的路径,我的是Syslog_csv.class,所以我最后那个是Syslog_csv。
不知道写的详不详细,每个人情况不一样,仅供参考,但是设置的时候环境变量是最重要的,我就是环境变量一直不对,总是按网上查到的来,不明白怎么回事,才一直出错,其实环境变量就是你要执行的java程序所在的位置,对了,.sh的执行是在终端输入sh

我要回帖

更多关于 linux驱动程序编写 的文章

 

随机推荐