Tag: shell

Ansible中如何做多行shell脚本

现在我正在使用一个shell脚本,如果它是多行的,那么这个脚本将更具可读性 – name: iterate user groups shell: groupmod -o -g {{ item['guid'] }} {{ item['username'] }} ….more stuff to do with_items: "{{ users }}" 只是不知道如何允许Ansible shell模块中的多行脚本

如何获得当前耙测任务的PID?

我把一个收割机放到一个耙子任务中,以杀死一些额外产生的ruby任务,因为它们偶尔会以某种方式蔓延。 system "ps aux | grep 'namespace:taskname' | grep ruby | grep -v grep | awk '{print $2}' | xargs kill -9; echo 'Reaped old namespace:taskname processes.'" 我想添加grep -v $PID_OF_CURRENT_TASK ,只是为了确保我不杀死当前正在运行的任务。 我如何获得PID?

Bash脚本,while循环中的多个条件

我试图得到一个简单的while循环在bash中使用两个条件,但在尝试从各种论坛的许多不同的语法后,我不能停止抛出一个错误。 这是我有什么: while [ $stats -gt 300 ] -o [ $stats -eq 0 ] 我也试过了: while [[ $stats -gt 300 ] || [ $stats -eq 0 ]] …以及其他几个构造。 我希望这个循环继续,而$stats is > 300或$stats = 0 。

Powershell:解决可能不存在的path?

我试图处理可能或可能不是最新的,可能存在或可能不存在的文件列表。 这样做,我需要解决一个项目的完整path,即使该项目可能指定相对path。 但是,与不存在的文件一起使用时, Resolve-Path打印并显示错误。 例如, 在Powershell "C:\Current\Working\Directory\newdir\newfile.txt" ".\newdir\newfile.txt"parsing为"C:\Current\Working\Directory\newdir\newfile.txt"的最简单,最简单的方法是什么? 请注意, System.IO.Path的静态方法与进程的工作目录一起使用 – 这不是powershell的当前位置。

有没有办法指出batch file中的最后n个参数?

在以下示例中,我想从父batch file中调用一个子batch file,并将所有其余parameter passing给子处理。 C:\> parent.cmd child1 foo bar C:\> parent.cmd child2 baz zoop C:\> parent.cmd child3 abcdefghijklmnopqrstu vwxyz 在parent.cmd里面,我需要从参数列表中去掉%1,并且只把剩下的参数传给子脚本。 set CMD=%1 %CMD% <WHAT DO I PUT HERE> 我已经调查使用SHIFT与%*,但不起作用。 当SHIFT将位置参数向下移动1时,%*仍然是指原始参数。 有人有主意吗? 我应该放弃并安装Linux?

shell脚本variables – 找不到命令

我有一个shell脚本,可以让我访问脚本中的全局variables,但是当我尝试创build自己的脚本时,它会响应:找不到命令。 #!/bin/bash J = 4 FACE_NAME = "eig$J.face" USER_DB_NAME = "base$J.user" 当我运行上面的脚本时,我得到: ./test1.sh line 2: J: command not found ./test1.sh line 3: FACE_NAME: command not found ./test1.sh line 4: USER_DB_NAME: command not found 有任何想法吗?? 我在Windows XP下使用Cygwin。

创buildzip文件的文件夹并解压缩

如果我select一个zip文件并右键单击“解压缩”,则会创build一个带有zip文件名的文件夹,并将zip文件的全部内容解压缩到该文件夹​​中。 不过,我想通过shell转换几个zip文件。 但是当我这样做 unzip filename.zip 文件夹"filename"不会被创build,但所有的文件被提取到当前目录中。 我已经看过参数,但没有这样的参数。 我也试过了 for zipfile in \*.zip; do mkdir $zipfile; unzip $zipfile -d $zipfile/; done 但2. $ zipfile和4. $ zipfile的.zip扩展名必须用sed删除。 如果我做 for zipfile in \*.zip; do mkdir sed 's/\.zip//i' $zipfile; unzip $zipfile -d sed 's/\.zip//i' $zipfile/; done 它不工作。 如何正确地replace$zipfile的.zip扩展名? 有比shell脚本更简单的方法吗?

在PowerShell中创build日志文件

我有下面的代码,目前它加载屏幕上的所有信息。 我希望它login到D:\ Apps \ Logs上的日志文件。 日志文件需要有它正在加载的计算机的名称 – 所以COMPUTERNAME.log 任何想法我怎么能做到这一点? 谢谢 $computer = gc env:computername $onetcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMajorPart).tostring() $twotcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductMinorPart).tostring() $threetcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductBuildPart).tostring() $fourtcp = ((get-childitem c:\windows\system32\drivers\tcpip.sys).Versioninfo.ProductPrivatePart).tostring() $onedfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductMajorPart).tostring() $twodfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductMinorPart).tostring() $threedfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductBuildPart).tostring() $fourdfsr = ((get-childitem c:\windows\system32\dfsrs.exe).Versioninfo.ProductPrivatePart).tostring() write-host TCPIP.sys Version on $computer is: "$onetcp.$twotcp.$threetcp.$fourtcp" Write-Host write-host […]

转换行结束符

我一直在使用d2u转换行结束符。 安装Puppy Linux后,我注意到它不是与d2u ,但dos2unix 。 然后我发现默认情况下Ubuntu缺失。 换行结束的另一种方法是什么?

在Windows 7 git-bash中,有没有办法在当前位置探索目录?

我想从shell中浏览Windows资源pipe理器中的文件夹。 我知道很多人一直在从一个文件夹询问Cmd。 我想做相反的事情,并打开一个新的窗口位于当前正在浏览的目录。