sh

Find a file that was created within five days of another file in shell

时间秒杀一切 提交于 2019-12-18 04:21:49
问题 i'm still pretty new to scripting so stick with me and if you have any questions please feel free to ask. Okay, so: I have a file let's say file.txt file.txt exists in a directory /this/is/the/directory/file.txt In a separate directory .log files exist that tell me what happens when file.txt was created. fuubar.log, fuu.log, bar.log, this.log, that.log, some.log, other.log ...there is an unknown number of these logs. I need to gather all the log files that occurred +-5 days of the file.txt

How to automatically create batch / shell scripts to run a Java console application?

萝らか妹 提交于 2019-12-18 02:48:24
问题 I have a Java command-line application, and would like to create an Ant* build script that will create all the required batch/shell scripts to run the application successfully including all the classpath variables. I need it to do the following: Create a shell script file for Linux/Unix and a batch file for Windows/DOS Add all classpath dependencies (from Maven or simply use the build path in Eclipse) Add any necessary boilerplate sh/bat code to run (ENV variables, JAVA_HOME, etc.) I found

How to automatically create batch / shell scripts to run a Java console application?

瘦欲@ 提交于 2019-12-18 02:47:01
问题 I have a Java command-line application, and would like to create an Ant* build script that will create all the required batch/shell scripts to run the application successfully including all the classpath variables. I need it to do the following: Create a shell script file for Linux/Unix and a batch file for Windows/DOS Add all classpath dependencies (from Maven or simply use the build path in Eclipse) Add any necessary boilerplate sh/bat code to run (ENV variables, JAVA_HOME, etc.) I found

How do you delete all lines that begin with “string” in unix sh?

前提是你 提交于 2019-12-17 23:23:12
问题 How do you delete all lines in a file that begin with "string" in sh? I was thinking about using the sed command. 回答1: grep -v '^string' yourfile.txt > stripped.txt 回答2: To do it in place, if your sed supports the -i option, you can do: sed -i '/^string/d' input-file 回答3: sed and grep in your answers are missing their friend awk: awk '!/^string/' inputfile > resultfile 回答4: You can use Vim in Ex mode: ex -sc g/^string/d -cx file g select all matching lines d delete x save and close 来源: https:

Shell: redirect stdout to /dev/null and stderr to stdout [duplicate]

走远了吗. 提交于 2019-12-17 21:44:50
问题 This question already has answers here : How to pipe stderr, and not stdout? (12 answers) Closed 3 years ago . I saw this interesting question at a comment on cyberciti.biz. That I found I even can't find a flexible way to do this in one-line command with sh. As far my thought for the solution is: tmp_file=`mktemp` (./script 2>$tmp_file >/dev/null; cat $tmp_file) | ./other-script rm tmp_file But you see, this is not synchronous, and fatally, it's so ugly. Welcome to share you mind about this.

Why does Scala use a reversed shebang (!#) instead of just setting interpreter to scala

会有一股神秘感。 提交于 2019-12-17 21:29:20
问题 The scala documentation shows that the way to create a scala script is like this: #!/bin/sh exec scala "$0" "$@" !# /* Script here */ I know that this executes scala with the name of the script file and the arguments passed to it, and that the scala command apparently knows to read a file that starts like this and ignore everything up to the reversed shebang !# My question is: is there any reason why I should use this (rather verbose) format for a scala script, rather than just: #!/bin/env

How do I get effect and usefuless of “set -e” inside a shell function?

南笙酒味 提交于 2019-12-17 20:44:53
问题 set -e (or a script starting with #!/bin/sh -e ) is extremely useful to automatically bomb out if there is a problem. It saves me having to error check every single command that might fail. How do I get the equivalent of this inside a function? For example, I have the following script that exits immediately on error with an error exit status: #!/bin/sh -e echo "the following command could fail:" false echo "this is after the command that fails" The output is as expected: the following command

Shell Script Syntax Error: Unexpected End of File [duplicate]

你。 提交于 2019-12-17 18:02:52
问题 This question already has answers here : Bash syntax error: unexpected end of file (17 answers) Closed 2 months ago . In the following script I get an error: syntax error: unexpected end of file What is this error how can I resove it? It is pointing at the line whee the function is called. #!/bin/sh expected_diskusage="264" expected_dbconn="25" expected_httpdconn="20" expected_cpuusage="95" #expected_fd="100" httpdconn=`ps -ef|grep -i httpd|grep -v grep|wc -l` #httpd connections cpu_usage=`ps

Shell Script Syntax Error: Unexpected End of File [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-17 18:02:43
问题 This question already has answers here : Bash syntax error: unexpected end of file (17 answers) Closed 2 months ago . In the following script I get an error: syntax error: unexpected end of file What is this error how can I resove it? It is pointing at the line whee the function is called. #!/bin/sh expected_diskusage="264" expected_dbconn="25" expected_httpdconn="20" expected_cpuusage="95" #expected_fd="100" httpdconn=`ps -ef|grep -i httpd|grep -v grep|wc -l` #httpd connections cpu_usage=`ps

Running two commands sequentially in a cron job?

这一生的挚爱 提交于 2019-12-17 18:00:59
问题 I have two commands in a cron job like this: mysql -xxxxxx -pyyyyyyyyyyv -hlocalhost -e "call MyFunction1";wget -N http://mywebsite.net/path/AfterMyFunction1.php but it seems to me that both of them are running at the same time. How can I make the first command run and when it completes, execute the second command? Also the AfterMyFunction1.php have javascript http requests that are not executed when I use wget. It works if I opened AfterMyFunction1.php in my webbrowser. 回答1: If the first