Articles of SH

什么是确定在Linux上运行哪个syslog守护进程的最佳方法?

我正在编写Linux shell脚本(sh,bash或csh)来确定哪个syslog守护进程正在运行。 什么是最好的办法呢? 由于我只考虑基于RHEL和rpm的版本,所以Debian及其派生版可以忽略。

sh脚本没有findvariables

我正在关注如何运行反向ssh隧道的教程,该教程可以在http://wiki.fabelier.org/index.php?title=Permanent_Reverse_SSH_Tunnelingfind我遇到的问题是当我运行tunneling.sh脚本时: #!/bin/sh a=`ps -ef | grep 19999 | grep -v grep` if [ ! "$a" ]; then ssh -fN -R 19999:localhost:22 <middle-usename>@<middle-hostname> fi 我收到这个错误: tunnel2.sh: 2: tunnel2.sh: a: not found 编辑: 我把shebang改成了#!/ bin / bash 现在我得到这个错误: tunnel2.sh: 2: tunnel2.sh: pi: not found

有效的赋值运算符Bash

在我的bash脚本中,我正在尝试使用equals(=)运算符作为IF语句的input,可以这样做吗? echo "Plese enter an operator as shown in the brackets (-)subtract, (*)Multiply, (+)Add, (/)divide, quit(=)?" read operator ………. if [[ $operator == '=' ]]; then 'do something' fi

任何方式来打印屏幕的内容到网页?

我在屏幕上运行一个minecraft服务器(屏幕-X mc java -jar minecraft_server.jar)。 有什么办法可以将这些内容打印到网页上? 我在想这将是一些事情 <?php $console = exec(console.sh) echo $console; header("refresh: 5";); ?> 但是这不会打印任何东西。 我认为这与每个用户的屏幕有关,有没有什么办法让PHP运行这个? 或者有无论如何输出屏幕的文件,仍然能够附加到屏幕上? 万分感谢! 编辑:下面的答案很好,但我会build议http://phpshell.sourceforge.net 。 您可以login到terminal并显示控制台并且可以聊天。 不过这是互动的,只能用于pipe理员。

将读取的variables转换为小写

我有以下情况: #!/bin/bash echo "Please enter a word:" read foobar 脚本在Ubuntuterminal中使用sh script.sh进行调用。 在互联网上search我find的解决scheme: foobar=${foobar,,} echo $foobar 上面的方法只适用于bash script.sh 于是我继续研究,发现: echo $foobar | tr '[:upper:]' '[:lower:]' 这确实对bash和sh ,但是没有echo,它就不起作用。 它也打印读取input两次,而不是像这样: ÿ ÿ 那么如何在不打印读取input两次的情况下对sh执行此操作?

在linux中读取一个属性文件

我想能够在Linux中读取一个属性文件,检查是否存在某些属性。 如果我正在寻找的属性存在,但他们不匹配我正在寻找的值,我想重写这些相应的属性。 如果他们不存在,那么我想写他们的文件。 任何Linux专家都可以帮助我解决这个问题。 提前致谢! 而且键名可以是pre1.pre2.pre3的forms,所以像pre1.pre2.pre3 = value 以下是属性文件 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.all.disable_ipv6 = 1 kernel.sysrq = 0 net.ipv4.ip_forward = 0 net.ipv4.tcp_syncookies = 1 net.ipv6.conf.all.forwarding = 0 net.ipv4.tcp_keepalive_time = 30 net.ipv4.tcp_keepalive_intvl = 5 net.ipv4.tcp_keepalive_probes = 5 我想基本上改变tcp的所有设置。

为什么下面的代码在退出1时停止?

我试着用下面的代码执行一个Linux命令,但是它不会给输出打印出口1.当我在Linuxterminal上执行命令时给出输出。当通过Java执行时,它给出了错误。请教build议。 JButton btnRunningtime = new JButton("RunningTime"); btnRunningtime.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { try{ textArea.setText(""); String s2=comboBox.getSelectedItem().toString(); p = Runtime.getRuntime().exec("ps -eo pid,comm,cmd,start,etime | grep -i "+s2); BufferedReader br = new BufferedReader( new InputStreamReader(p.getInputStream())); while ((s = br.readLine()) != null) { textArea.append(s+"\n"); System.out.println("Running time "+s); } p.waitFor(); System.out.println ("exit: " + p.exitValue()); p.destroy(); } catch(Exception […]

Linux sh脚本将句子拆分成单词

我有一个脚本,input一个句子到$1 。 我怎样才能将$1 (比如"abcde"分割成a个别的单独的对象? 使用sh不bash 。

sh:2:1:未find – 将多个phpparameter passing给bash脚本

我有一个简单的bash脚本,我从我的php代码中调用,找出我的apache和nginx的版本。 $webroot = getcwd(); function get_version($name) { global $webroot; switch ($name) { case "apache": $path = shell_exec("whereis apachectl | awk '{ print $2 }'"); $version = shell_exec("sudo $webroot/scripts/get_version $path 1 2>&1"); break; case "nginx": $path = shell_exec("whereis nginx | awk '{ print $2 }'"); $version = shell_exec("sudo $webroot/scripts/get_version $path 2 2>&1"); default: echo "error"; } […]

我可以在shell脚本中使用hexdump吗?

我可以在shell脚本中使用hexdump吗? 当我使用它时,我不断收到错误。 在意外标记'hexdump'附近的语法错误 #!/bin/bash #bash-hexdump # Quick script to check delay of the shotpoints echo " please enter the complete line name as mentioned in the RAID2 " read $line cd /argus/raid2/"$line" echo echo " Entering the directory " echo for file in /argus/raid2/"$line"/*.ffid hexdump -e "16 \"%_p\" \"\\n\"" $FFID | sed -n '68,73p' > […]