scripting

How to make a bash script that creates 40 simultaneous instances of a program?

会有一股神秘感。 提交于 2019-12-21 11:30:05
问题 I am new to bash and Linux . I have a program I have written that I want to create multiple simultaneous instances of. Right now, I do this by opening up 10 new terminals, and then running the program 10 times (the command I run is php /home/calculatedata.php What is the simplest way to do this using a bash script? Also, I need to know how to kill the instances because they are running an infinite loop. Thanks!! 回答1: You can use a loop and start the processes in the background with & : for ((

Are there any escaping syntax for psql variable inside PostgreSQL functions?

只愿长相守 提交于 2019-12-21 09:28:11
问题 I write PSQL script and using variables (for psql --variable key=value commandline syntax). This works perfectly for top level scope like select * from :key , but I create functions with the script and need variable value inside them. So, the syntax like create function foo() returns void as $$ declare begin grant select on my_table to group :user; end; $$ language plpgsql; fails at :user . As far as I understand psql variables is a plain macro substitution feature, but it doesn't process

The number of processes a user is running using bash

ぃ、小莉子 提交于 2019-12-21 07:52:49
问题 I would like to know how I could get the number of processes for each user that is currently logged in. 回答1: Give this a try: ps -u "$(echo $(w -h | cut -d ' ' -f1 | sort -u))" o user= | sort | uniq -c | sort -rn In order to properly handle usernames that may be longer than eight characters, use users instead of w . The latter truncates usernames. ps -u "$(echo $(printf '%s\n' $(users) | sort -u))" o user= | sort | uniq -c | sort -rn 回答2: You could try some variation of this: ps haux Ou | cut

The number of processes a user is running using bash

早过忘川 提交于 2019-12-21 07:51:11
问题 I would like to know how I could get the number of processes for each user that is currently logged in. 回答1: Give this a try: ps -u "$(echo $(w -h | cut -d ' ' -f1 | sort -u))" o user= | sort | uniq -c | sort -rn In order to properly handle usernames that may be longer than eight characters, use users instead of w . The latter truncates usernames. ps -u "$(echo $(printf '%s\n' $(users) | sort -u))" o user= | sort | uniq -c | sort -rn 回答2: You could try some variation of this: ps haux Ou | cut

Bash 'for' loop syntax?

两盒软妹~` 提交于 2019-12-21 07:29:16
问题 What is the syntax for a Bash for loop? I have tried: for (($i=0;$i<10;$i ++)) do echo $i done I get this error: line 1: ((: =0: syntax error: operand expected (error token is "=0") 回答1: Replace for (($i=0... with for ((i=0;i<10;i++)) 回答2: The portable way is: for i in `seq 0 9` do echo "the i is $i" done 回答3: Another way for i in {0..9} do echo $i done 来源: https://stackoverflow.com/questions/6854118/bash-for-loop-syntax

powershell -split('') specify a new line

不羁的心 提交于 2019-12-21 07:13:49
问题 Get-Content $user| Foreach-Object{ $user = $_.Split('=') New-Variable -Name $user[0] -Value $user[1]} Im trying to work on a script and have it split a text file into an array, splitting the file based on each new line What should I change the "=" sign to 回答1: It depends on the exact encoding of the textfile, but [Environment]::NewLine usually does the trick. "This is `r`na string.".Split([Environment]::NewLine) Output: This is a string. 回答2: The problem with the String.Split method is that

Return value from a Java code

心不动则不痛 提交于 2019-12-21 06:58:53
问题 There is a Java class which creates a POST request and sends it to a servlet. The main method of the class file (test) looks something like this: public static void main(String[] args) throws IOException { // Code logic goes here... // No return Statement } This is called from a KornShell (ksh) script something like this: retcode=`$CLK_JAVA_PATH -cp $CLASSPATH test ${PASSWORD} ${HOSTNAME} ${TOOLSET}` if [ $? != "0" ];then echo "ERROR: echo "${retcode}" else echo "${SCRIPT} Success" fi retcode

Want to script Windows WMI (wmiprvse.exe) to release handle on file

爱⌒轻易说出口 提交于 2019-12-21 06:45:06
问题 I'm working with a VB Script file written by someone else that uses Windows Management Instrumentation (WMI) calls to check on the status of several Windows Services. This script runs every few minutes on set schedule. I need to upgrade/replace the .exe for those services. I stop the VB Script, stop the services, and uninstall the services so they no longer appear in the Services panel (services.msc). Unfortunately, WMI (wmiprvse.exe) still has a handle on the service .exe files. I can

Automating Nuget Package Push With .NetCore RC2

浪尽此生 提交于 2019-12-21 05:41:20
问题 I am currently working on a .NET Core library that I am going to use as a NuGet package in another project. I have been able to successfully package the project using the "dotnet pack" command in the project directory, and upload that package to MyGet. I would prefer to automate this process of pushing the NuGet package by using the "nuget push" command. My issue is that the "scripts" property defined in the project.json file does not seem to be executed on pack or build. I expected that

In Scala, is it possible to write a script which refers to another script

蓝咒 提交于 2019-12-21 05:06:49
问题 I am currently looking at using Scala scripts to control the life-cycle of a MySQL database instead of using MS-DOS scripts (I am on Windows XP). I want to have a configuration script which only holds configuration information, and 1 or more management scripts which use the configuration information to perform various operations such as start, stop, show status, etc ..... Is it possible to write a Scala script which includes/imports/references another Scala script? I had a look at the -i