sh

Exit tail upon string detection

为君一笑 提交于 2019-12-11 03:06:41
问题 I'm writing a barrier to stop to hold the execution of a script until a certain keyword is logged. The script is pretty simple: tail -F -n0 logfile.log | while read LINE; do [[ "$LINE" == *'STOP'* ]] && echo ${LINE} && break; done or tail -F -n0 logfile.log | grep -m1 STOP Still, despite printing STOP as soon as it is detected, these chunks of code terminate only after the following line is written . I.e: printf "foo\n" >> logfile.log # keeps reading printf "foo\n" >> logfile.log # keeps

Can you spawn a process in a shell script?

混江龙づ霸主 提交于 2019-12-11 02:56:43
问题 I'm trying to get my #!/bin/sh shell script to start another application without pausing execution. That is I'm looking for a way to launch it in the background and have my shell script keep executing. I want it to work something like this: # start daemon start(){ success=`launch '/path/to/daemon'` if [ $success != false ];then echo 'daemon is now running' fi I'm also new to shell scripting so will the above (if launch existed) get the return of launch or the stdout set as $success? I want to

Force node.js to use bin/bash instead of sh

主宰稳场 提交于 2019-12-11 02:49:22
问题 I'm trying to execute a basic bash script from node using the exec() function. The bash script is as follows: #!/bin/bash ffmpeg -f concat -i <(for f in $1/*.mov ; do echo "file '$f'"; done) -c copy $1/output.mov The script works fine running it from the command line but when running from within node I get a syntax error: line 2: syntax error near unexpected token ('` It appears when running this command node it attempting to use sh instead of bash . Can anyone verify this is true and give a

How can I find the current date minus seven days in Unix?

人盡茶涼 提交于 2019-12-11 02:41:06
问题 I am trying to find the date that was seven days before today. CURRENT_DT=`date +"%F %T"` diff=$CURRENT_DT-7 echo $diff I am trying stuff like the above to find the 7 days less than from current date. Could anyone help me out please? 回答1: GNU date will to the math for you: date --date "7 days ago" Other version will require you to covert the current date into seconds since the UNIX epoch first, manually subtract 7 days' worth of seconds, and convert that back into the desired form. Consult

Is it possible to several commands in the background but wait for all results and fail the script if an command fails

血红的双手。 提交于 2019-12-11 01:47:46
问题 I have a CI script that I want to speed up by running several things in the background. I want the script wait for all processes and check each one to see if it failed. Here a a simplification: #!/bin/bash set -e bg() { sleep .$[ ( $RANDOM % 10 ) + 1 ]s } bg2() { sleep .$[ ( $RANDOM % 10 ) + 1 ]s exit 1 } bg & # will pass after a random delay bg2 & # will fail after a random delay # I want the output of the program to be a failure since bg2 fails 回答1: Yes. You can use the wait command in bash

subprocess.call not working from pyCharm

时光毁灭记忆、已成空白 提交于 2019-12-11 01:17:53
问题 My file structure is: ├── src │ ├── main │ │ ├── costSensitiveClassifier.py └── vowpal.sh | ├── data │ ├── output │ │ ├── cost | | |_______openCostClassifier.dat | | | And within costSensitiveClassifier.py , I essentially am trying to run a script called vowpal.sh that does some manipulations on openCostClassifer.dat and outputs some files into the same folder as that file. The code within costSensitiveClassifier.py is: import subprocess print "Starting cost sensitive predictions using batch

Shell script: How to prevent SIGINT from interrupting current task

孤街醉人 提交于 2019-12-11 01:15:47
问题 I have a quite long shell script and I'm trying to add signal handling to it. The main task of the script is to run various programs and then clean up their temporary files. I want to trap SIGINT. When the signal is caught, the script should wait for the current program to finish execution, then do the cleanup and exit. Here is an MCVE: #!/bin/sh stop_this=0 trap 'stop_this=1' 2 while true ; do result="$(sleep 2 ; echo success)" # run some program echo "result: '$result'" echo "Cleaning up...

Copy ffmpeg bins in multistage docker build

别等时光非礼了梦想. 提交于 2019-12-11 00:16:27
问题 I'm trying to install ffmpeg via a multistage docker build Here is the ffmpeg image that contains the ffmpeg binaries FROM jrottenberg/ffmpeg Here is the pm2 image that I need to run my web server FROM keymetrics/pm2:8-alpine I copy the bins into the current image, and I can see that ffmpeg, ffserver, and ffprobe all exist in /usr/local/bin. COPY --from=0 /usr/local /usr/local The copy command appears to succeed, since those files exist when I run the container interactively. $# which ffmpeg

How to recursively resolve symlinks without readlink or realpath?

独自空忆成欢 提交于 2019-12-10 19:02:44
问题 What's the best portable (POSIX?) way to script finding the target for a link if readlink and realpath are not available? Would you ls -l , and if it starts with l take the text after the -> with sed and repeat until it no longer starts with l ? 回答1: Per BashFAQ #29 (which also endorses the GNU find approach suggested by @EugeniuRosca): One widely available (though not pure-POSIX) option is to use perl : target=/path/to/symlink-name perl -le 'print readlink $ENV{target}' If your symlink's

Using bash, how can I remove the extensions of all files in a specific directory?

℡╲_俬逩灬. 提交于 2019-12-10 18:27:40
问题 I want to keep the files but remove their extensions. The files do not have the same extension to them. My end goal is to remove all their extensions and change them to one single extension of my choice. I have the second part down. My code so far: #!/bin/bash echo -n "Enter the directory: " read path #Remove all extensions find $path -type f -exec mv '{}' '{}'.extension \; #add desired extension 回答1: You don't need an external command find for this, but do it in bash alone. The script below