scripting

Correct way to use Linux commands in bash script

半腔热情 提交于 2019-12-24 02:04:15
问题 What is the best and most correct way to use Linux commands in bash scripts in terms of path to it? Is that correct to use only ip addr show , relying on shell path, or should I find a path to the command first (like with whereis ip or command -v ip ), assign the output to some variable and then use that? 回答1: Personally, I just rely on the PATH and invoke "bare" commands. If you don't trust the user's PATH, you can reset it to a minimal default: PATH=$(/usr/bin/getconf PATH) grep "$pattern"

How do I export all pages below a page in confluence using a script

亡梦爱人 提交于 2019-12-24 01:58:16
问题 I'm capturing meeting notes in a page structure in confluence. I want to export all the meeting notes to a share drive for others to read. I've found notes on how to export a page or a space but not the pages below a page. e.g. I want everything below "Parent Page" but not anything else. e.g. Space Unrelated Pages Unrelated Pages Parent of Parent Parent Page Child Page 1 Child Page 2 Child page 3 I want to drag the child pages to a share drive. I'm looking to use one of the following e.g.

Why is 'cp' failing in this shell script?

别来无恙 提交于 2019-12-24 01:26:11
问题 Here's a snippet of code from a shell script I have written: for src in $(find . -type f -maxdepth 1 \! -name ${deploy} \! -name gvimrc) do src=$(basename ${src}) dest="~/.${src}" copy="${src} -> ${dest}" cp $src $dest && echo -e "${ok} ${copy}" || echo -e "${fail} ${copy}" done For some reason, cp fails to execute. For example, in the case in which $src='bashrc' , I get this error: cp: ~/.bashrc: No such file or directory I don't understand why this happens, though, because obviously, ~/

Loading HTML content containing inline script via jQuery

懵懂的女人 提交于 2019-12-24 00:54:46
问题 The Background I run an ASP.NET site using Graffiti CMS for a local charitable/service organization. The leaders of the organization want to start integrating a third-party back-end management system that exposes content as full HTML pages. One of the pages, the officer list, uses inline script to load pictures or placeholders (depending on whether or not there is a picture for the given officer). I've created a server-side proxy that enables loading the content from these pages using jQuery

how to compress log files older than 30 days in windows?

耗尽温柔 提交于 2019-12-24 00:36:31
问题 I write below powershell script to compress logs older than 30 days:- $LastWrite=(get-date).AddDays(-30).ToString("MM/dd/yyyy") Get-ChildItem -Filter "server.log*" -Recurse -File | Where-Object {$_.LastWriteTime -le $LastWrite} Now, I am unable to get compressed command in powershell via which I can compress(zip/tar) the server.log* files older than 30 days. Expecting a single command which i can use by adding a pipe sign in the above command. 回答1: You can use the Compress-Archive cmdlet to

printing variable inside awk

情到浓时终转凉″ 提交于 2019-12-24 00:11:28
问题 In this script , I want awk to print the variables $file , $f , $order and sum/NR (all in a single row) #!/bin/bash for file in pmb_mpi tau xhpl mpi_tile_io fftw ; do for f in 2.54 1.60 800 ;do if [ ${f} = 2.54 ] then for order in even odd ; do # echo ${file}_${f}_${order}_v1.xls >> P-state-summary.xls awk '{sum+=$2} END {print ${file}_${f}_${order}_v1.xls, sum/NR}' ${file}_${f}_${order}_v1.xls >> P-state-summary.xls done else # echo ${file}_${f}_v1.xls >> P-state-summary.xls awk '{sum+=$2}

How to get the last N lines of a subprocess' stderr stream output?

孤街浪徒 提交于 2019-12-23 22:31:40
问题 I am a Python newbie writing a Python (2.7) script that needs to exec a number of external applications, one of which writes a lot of output to its stderr stream. What I am trying to figure out is a concise and succinct way (in Python) to get the last N lines from that subprocess' stderr output stream. Currently, I am running that external application from my Python script like so: p = subprocess.Popen('/path/to/external-app.sh', stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr

Why do I use double quotes in shell scripts [duplicate]

醉酒当歌 提交于 2019-12-23 20:29:45
问题 This question already has answers here : When to wrap quotes around a shell variable? (5 answers) Closed 3 years ago . I understand the usage single quote and double quote. but I don't know situation need to double quotes in the script. there is no diff that statements $ echo hello world! $1 $ echo "hello world! $1" please show me diff between normal and double quotes. 回答1: Let's consider a directory with these files: $ ls foo* foo111.txt foo11.txt foo1.txt Let's consider a minor variation on

Why doesn't implementing IObjectSafety make a difference?

戏子无情 提交于 2019-12-23 19:52:48
问题 we have an activex object which implements IObjectSafety to indicate that it is safe for scripting. It installs from a trusted site. but we still get the IE complaint that the control on this page is not safe for scripting. The admins for the site that are running our activex are reluctant to enable controls not marked safe for scripting even though its the trusted zone. our cab and all its components are signed (we finally made the uverified publisher go away by signing every dll that went

PowerShell: Set-Content having issues with “file already in use”

允我心安 提交于 2019-12-23 19:43:30
问题 I'm working on a PowerShell script that finds all the files with PATTERN within a given DIRECTORY, prints out the relevant lines of the document with the PATTERN highlighted, and then replaces the PATTERN with a provided REPLACE word, then saves the file back. So it actually edits the file. Except I can't get it to alter the file, because Windows complains about the file already being open. I tried several methods to solve this, but keep running into the issue. Perhaps someone can help: param