Hot answers tagged

4

Parameter substitution can be used to strip string prefixes from the JENKINS_URL. From the ksh man page: ${name#pattern}, ${name##pattern} If pattern matches the beginning of the value of parameter name, the matched text is deleted from the result of substitution. A single # results in the shortest match, two #'s results in the longest match. As an ...


2

time does not time commands. From the Single Unix Specification's rationale: The term utility is used, rather than command, to highlight the fact that shell compound commands, pipelines, special built-ins, and so on, cannot be used directly. The SUS also states that the result of time on special built-in commands is undefined, and its results when used on ...


2

POSIXly (assuming $yearmonth doesn't have leading zeros): case $((yearmonth += 1)) in (*13) yearmonth=$((yearmonth + 100 - 12)) esac With ksh/bash/zsh, you could shorten it to: ((++yearmonth % 100 <= 12)) || ((yearmonth += 100 - 12))


2

Assuming that you are located in the directory that holds the listed files, using zsh: ls -ld shop4_0_Log<331882->.Z The <331882-> is a zsh-specific glob that matches integers that are 331882 or larger. With some other shell: for name in shop4_0_Log*.Z; do number=${name#shop4_0_Log} number=${number%.Z} if [ "$number" -ge 331882 ];...


1

ping returns a different exit code depending on how successful it is. There are multiple implementations of ping that may behave slightly differently, but quoting from one of their manpages If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are ...


1

You can use ping's exit value to know if the host is up: 0 everything ok 1 no response or lost packages 2 other errors (unable to resolve is one of them) So, this for example: ping -c 5 hostname || error_script.sh will run error_script.sh only if something went wrong.


1

Another good tool would be sed: sed -n '/shop4_0_Log0000331881\.Z$/q;p' test.out


1

I think you can just use awk directly: awk '/331881/ { exit } 1' test.out This will print all lines, but for a line matching 331881, quit.


1

You can consider the neater command netcat aka nc as discussed here echo 'QUIT' | nc -w SECONDS YOUR_HOST PORT; echo $?


1

#!/bin/ksh JENKINS_URL=$1 # extract just the host and potental port number from the url HOSTP=${JENKINS_URL#*:} ; HOSTP=${HOSTP%%/*} # Create down directory if it doesn't exist [ -d down ] || mkdir -p down curl --connect-timeout 10 "$JENKINS_URL" >/dev/null status=$? if [ "$status" == "7" ]; then [ -e "down/$HOSTP" ] && exit 0 { echo -n ...


1

Or (( yearmonth += ((yearmonth % 100) == 12)?(100 - 11):1 ))


Only top voted, non community-wiki answers of a minimum length are eligible