Articles of bash

不同的bashpathvariables使用ssh脚本vs交互式ssh

我试图通过脚本使用Plink运行一些ruby(bundler / rvm)命令。 我注意到这是抱怨不知道某些命令在哪里。 看起来好像我的$PATHvariables不同于我使用交互式shell的时候,以及当我用Plink指定一个命令文件的时候。 在我的.bash_profile我有这个: [[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* 如果我理解正确,当不在交互模式时,应该读取.bashrc而不是.bash_profile 。 所以,如果这是正确的,这是我的.bashrc的最后一行: export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting 那会告诉我,我应该在我的道路上看到,但我不知道。 这是我得到我的$PATH : /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 这看起来像我默认的$PATHvariables。 为什么当我尝试通过ssh运行命令时,我的.bashrc不会被find? 我已经添加echo "the […]

初始化脚本中的脚本名称

我有一个脚本/etc/init.d/startup ,在那里我做到以下几点: 创build一个应该如下所示的PID文件:/ /var/run/**startup**.pid 执行一个java进程的屏幕,所以我想创build一个名称为startup的屏幕(就像这个屏幕的“dmS 启动 ”脚本的path一样) 在服务器运行的时候,我没有任何问题,但是当它启动时,它会创buildPIDfile和屏幕,其名称不正确: /var/run/**S92startup**.pid 2058.**S92startup** (11/10/2014 03:56:31 PM) (Detached) 如何在启动时指定脚本的名称? (而不是/etc/rc2.d/中的符号链接的名称) 现在我的脚本看起来像这样开始,这就是我得到脚本的名字 SCRNAME=${0##*/} DAEMON="screen -DmS $SCRNAME /srv/startup/scripts/gprs.sh" PIDFILE=/var/run/$SCRNAME.pid PS:它是正确的,当我在服务器上,执行“服务启动启动”,而不是在启动时。

如何最好地维护亚马逊linux上最近的bash版本?

我需要Bash 4.2或更高版本。 Amazon Linux默认存储库仅提供Bash 4.1。 我做了一些search,找不到最近版本的Bash的yum存储库。 我不想从源代码编译,因为我想外包跟踪错误修复(例如Shellshock )。 我正在寻找一个百胜的回购,我可以安装最近的Bash二进制文件,或另一种可行的方式来保持在服务器上的最新版本的Bash。 这是有问题的节点之一的yum输出: [ec2-user@nodeX ~]$ sudo yum install bash Loaded plugins: priorities, update-motd, upgrade-helper 33 packages excluded due to repository priority protections Package bash-4.1.2-15.23.amzn1.x86_64 already installed and latest version Nothing to do 请注意,这是我之前在“Unix和Linux”堆栈交换站点上的问题的一个交叉点 。

SSH问题:密钥文件和主机文件无法正常工作

当我用密钥login到服务器 ssh -i /home/me/.ssh/id_rsa server 一切都没有问题。 密钥在服务器上被授权。 但是,如果我尝试从一个shell脚本做同样的事情,我得到一个密码请求。 当我尝试使用密钥文件scp时也是如此: scp -i /home/me/.ssh/id_rsa file server: 我也为主机创build了〜/ .ssh / config: Host server hostname server IdentityFile /home/me/.ssh/id_rsa 当我尝试SSH与ssh server我也得到一个密码请求。 密钥文件,sshconfiguration和服务器的authorized_keys具有设置为600的权限。 我能做些什么来解决这个问题? 编辑 sshfs也一样。 sshfs -o IdentityFile=/home/me/.ssh/id_rsa server:/directory mountpoint 从cli工作正常。 当它在一个shell脚本中时,我得到一个密码请求。

为Apache httpd加载OpenMPI模块

我该如何告诉Apache httpd要使用哪个版本的MPI? 我试图在Apache httpd下运行一个Django Web应用程序,并且我们的一些页面使用mpi4py进行MPI调用。 问题是当页面试图导入MPI时,我得到一个ImportError。 ImportError:libmpi.so.1:无法打开共享目标文件:没有这样的文件或目录 服务器同时安装了OpenMPI和MPICH,并且在用户shell中,我必须键入module load openmpi/gnu才能使用mpi4py。 例如,这将会导致加载库时出错: python -c "from mpi4py import MPI" 我用这行创build一个/etc/profile.d/openmpi.sh文件解决了用户shell的问题: module load openmpi/gnu 不幸的是,这听起来像Apache用户不加载全局configuration文件,所以我仍然在我的页面中的ImportError。 我尝试在/etc/sysconfig/httpd的末尾加载模块: . /etc/profile.d/modules.sh module load openmpi/gnu 不幸的是,我仍然得到ImportError。 如果我注释掉导入并检查os.environ['PATH'] ,看起来openmpi模块还没有加载,所以加载Apache服务的shell不能与运行Apache服务的shell相同。 我也尝试在/etc/bashrc进行更改,但似乎也不影响apache用户。 我们使用CentOS 5.9在Scyld Beowulf群集上运行Apache 2.2.3。

如何在haproxy中使用环境variables?

我使用haproxy 1.5.2我的haproxy.cfg有这个服务器定义: server HALB_ucd1 ${UCD1_END_POINT_IP}:${UCD1_END_POINT_PORT} check port 8444 我在bash中设置了UCD1_END_POINT_IP和UCD1_END_POINT_PORT,并使用haproxy重启服务启动haproxy haproxy重新启动,但UCD1_END_POINT_IP和UCD1_END_POINT_PORT未parsing。 我看到,按照haproxy文档它是支持的: Any part of the address string may reference any number of environment variables by preceding their name with a dollar sign ('$') and optionally enclosing them with braces ('{}'), similarly to what is done in Bourne shell. 如果我改变它硬编码的IP和端口它工作正常。 我错过了什么? 谢谢!

Powershell使用SQLPLUS执行查询

我有安装Oracle 10G的RHEL服务器。 我需要编写一个PowerShell脚本来查询我的数据库并获得输出。 我已经导入了Posh-SSH模块,并且能够连接到我的RHEL服务器并使用Invoke-SSHCommand执行命令,但是,我需要使用Invoke-SSHCommand来执行sqlplus命令。 通常情况下,我们可以使用EOF在perl中实现这一点,但是我们无法find任何方式使用PowerShell来完成这个任务。 使用EOF的Perl代码: $command="export ORACLE_SID=database sqlplus -S user/password<< EOF set feedback off select username from dba_users; EOF" 我的Powershell代码: $command="export ORACLE_SID=database sqlplus -S user/password<< EOF set feedback off select username from dba_users; EOF" $result = Invoke-SSHCommand -Index 0 -Command $command Write-Output $result 我的Powershell输出: Host : XX.XX.XXX.XXX Output : ExitStatus : 127 我猜,EOF字符可以被Powershell理解。 任何人都可以帮助我转换为PowerShell? […]

如何使用许可证密钥文件打包shell脚本文件

我正在处理特定任务的自动shell脚本。 在执行任务步骤之前,我想validation通过web服务调用提供给客户的许可证密钥。 请帮助我制作这两个文件(shell脚本和许可证文件)的包(.deb或任何其他),以便最终用户使用简单的命令自动运行。 我提供了示例许可证文件的shell脚本的初始部分 部分shell脚本: #/bin/sh function pause(){ read -p "$*" } file="./license.properties" url="webserviceurl" if [ -f "$file" ] then echo "$file found." . $file echo "sourcing of file is done" echo $productName" "$productVersion "license information" echo "Name of customer =" $customerName echo "license key of customer =" $licenseId else echo "license properties file not […]

Linux:通过运行yppasswd,更新passwd.byuid会导致随机失败的原因是什么?

为了允许我公司的NOC用户通过NISpipe理用户,我创build了以下脚本: #!/bin/bash # This script will simplicate NIS user management. # You will not be able to change password or delete users peeradmin and root through this script. # Written by Itai Ganot 2014. # Edit only this variable: PROTECTEDUSERS="peeradmin root" # Separate values with spaces. # Variables USER=$1 GREP="/bin/grep" PASSWDFILE="/etc/passwd" YPPASSWD="/usr/bin/yppasswd" USERDEL="/usr/sbin/userdel" USERADD="/usr/sbin/useradd" PASSWD="/usr/bin/passwd" […]

如何整理sar -d磁盘输出

sar -D输出 – 我想要一个合适的命令与压力-hdd一起运行,但是这是sar -D10给出的输出。 我用awk |'NR > 1 {printf "%4s%8s%8s\n",$13,$14,$15}'和awk 'NR > 1 {OFS="\t"; print $13,$14,$15}' awk 'NR > 1 {OFS="\t"; print $13,$14,$15}'但是输出如下面的第一个实例一样混乱。 我怎样才能把它过滤得更像我在ibm站点得到的第二个输出? 4296roryhbmc 1944 rootal, 3361 root Tasks: 326total, Cpu(s):25.7%us,54.1%sy, Mem:2041916k Swap:1046524kt 0 | 0 0 | 0 0 | 268 957 34 17 49 0 0 0| 0 0 | 0 […]